From a2cd83a98670b7dd03aeb41334d6e2fb030048af Mon Sep 17 00:00:00 2001 From: Andrea Canciani Date: Wed, 15 Jun 2011 15:27:21 +0200 Subject: [PATCH] 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. --- src/cairo-toy-font-face.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cairo-toy-font-face.c b/src/cairo-toy-font-face.c index 4c690da53..b82d8b06a 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 ();