[cairo-commit] src/cairo-scaled-font.c

Chris Wilson ickle at kemper.freedesktop.org
Tue Feb 28 07:07:45 PST 2012


 src/cairo-scaled-font.c |   54 ++++++++++++++++++++----------------------------
 1 file changed, 23 insertions(+), 31 deletions(-)

New commits:
commit 4429c7a3016622f9a31af6b6b9ff353e896885db
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Tue Feb 28 15:05:57 2012 +0000

    scaled-font: Refactor the hash computation
    
    Remove the cut'n'paste duplication and replace the hash computation with
    a proper function.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index e70c178..934b297 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -602,6 +602,26 @@ _hash_mix_bits (uint32_t hash)
     return hash;
 }
 
+static uint32_t
+_cairo_scaled_font_compute_hash (cairo_scaled_font_t *scaled_font)
+{
+    uint32_t hash = FNV1_32_INIT;
+
+    /* We do a bytewise hash on the font matrices */
+    hash = _hash_matrix_fnv (&scaled_font->font_matrix, hash);
+    hash = _hash_matrix_fnv (&scaled_font->ctm, hash);
+    hash = _hash_mix_bits (hash);
+
+    hash ^= (unsigned long) scaled_font->original_font_face;
+    hash ^= cairo_font_options_hash (&scaled_font->options);
+
+    /* final mixing of bits */
+    hash = _hash_mix_bits (hash);
+    assert (hash != ZOMBIE);
+
+    return hash;
+}
+
 static void
 _cairo_scaled_font_init_key (cairo_scaled_font_t        *scaled_font,
 			     cairo_font_face_t	        *font_face,
@@ -609,8 +629,6 @@ _cairo_scaled_font_init_key (cairo_scaled_font_t        *scaled_font,
 			     const cairo_matrix_t       *ctm,
 			     const cairo_font_options_t *options)
 {
-    uint32_t hash = FNV1_32_INIT;
-
     scaled_font->status = CAIRO_STATUS_SUCCESS;
     scaled_font->placeholder = FALSE;
     scaled_font->font_face = font_face;
@@ -622,19 +640,8 @@ _cairo_scaled_font_init_key (cairo_scaled_font_t        *scaled_font,
     scaled_font->ctm.y0 = 0.;
     _cairo_font_options_init_copy (&scaled_font->options, options);
 
-    /* We do a bytewise hash on the font matrices */
-    hash = _hash_matrix_fnv (&scaled_font->font_matrix, hash);
-    hash = _hash_matrix_fnv (&scaled_font->ctm, hash);
-    hash = _hash_mix_bits (hash);
-
-    hash ^= (unsigned long) scaled_font->font_face;
-    hash ^= cairo_font_options_hash (&scaled_font->options);
-
-    /* final mixing of bits */
-    hash = _hash_mix_bits (hash);
-
-    assert (hash != ZOMBIE);
-    scaled_font->hash_entry.hash = hash;
+    scaled_font->hash_entry.hash =
+	_cairo_scaled_font_compute_hash (scaled_font);
 }
 
 static cairo_bool_t
@@ -1121,22 +1128,7 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
     scaled_font->original_font_face =
 	cairo_font_face_reference (original_font_face);
 
-    {
-	uint32_t hash = FNV1_32_INIT;
-
-	/* We do a bytewise hash on the font matrices */
-	hash = _hash_matrix_fnv (&scaled_font->font_matrix, hash);
-	hash = _hash_matrix_fnv (&scaled_font->ctm, hash);
-	hash = _hash_mix_bits (hash);
-
-	hash ^= (unsigned long) scaled_font->original_font_face;
-	hash ^= cairo_font_options_hash (&scaled_font->options);
-
-	/* final mixing of bits */
-	hash = _hash_mix_bits (hash);
-	assert (hash != ZOMBIE);
-	scaled_font->hash_entry.hash = hash;
-    }
+    scaled_font->hash_entry.hash = _cairo_scaled_font_compute_hash(scaled_font);
 
     status = _cairo_hash_table_insert (font_map->hash_table,
 				       &scaled_font->hash_entry);


More information about the cairo-commit mailing list