[cairo-commit] src/cairo-toy-font-face.c

Andrea Canciani ranma42 at kemper.freedesktop.org
Thu Jun 16 03:20:59 PDT 2011


 src/cairo-toy-font-face.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

New commits:
commit a2cd83a98670b7dd03aeb41334d6e2fb030048af
Author: Andrea Canciani <ranma42 at gmail.com>
Date:   Wed Jun 15 15:27:21 2011 +0200

    toy-font-face: Do not assume hash != 0
    
    The assumption that no font face will hash to 0 is not correct.
    Moreover, no special value is needed to mark fonts in error status, as
    they can simply be detected upon lookup and destruction.

diff --git a/src/cairo-toy-font-face.c b/src/cairo-toy-font-face.c
index 4c690da..b82d8b0 100644
--- a/src/cairo-toy-font-face.c
+++ b/src/cairo-toy-font-face.c
@@ -148,7 +148,6 @@ _cairo_toy_font_face_init_key (cairo_toy_font_face_t *key,
     hash += ((unsigned long) slant) * 1607;
     hash += ((unsigned long) weight) * 1451;
 
-    assert (hash != 0);
     key->base.hash_entry.hash = hash;
 }
 
@@ -312,7 +311,6 @@ cairo_toy_font_face_create (const char          *family,
 
 	/* remove the bad font from the hash table */
 	_cairo_hash_table_remove (hash_table, &font_face->base.hash_entry);
-	font_face->base.hash_entry.hash = 0;
     }
 
     /* Otherwise create it and insert into hash table. */
@@ -366,7 +364,12 @@ _cairo_toy_font_face_destroy (void *abstract_face)
 	return;
     }
 
-    if (font_face->base.hash_entry.hash != 0)
+    /* Font faces in SUCCESS status are guaranteed to be in the
+     * hashtable. Font faces in an error status are removed from the
+     * hashtable if they are found during a lookup, thus they should
+     * only be removed if they are in the hashtable. */
+    if (likely (font_face->base.status == CAIRO_STATUS_SUCCESS) ||
+	_cairo_hash_table_lookup (hash_table, &font_face->base.hash_entry) == font_face)
 	_cairo_hash_table_remove (hash_table, &font_face->base.hash_entry);
 
     _cairo_toy_font_face_hash_table_unlock ();


More information about the cairo-commit mailing list