[cairo-commit] 3 commits - src/cairo-cache.c src/cairo-cache-private.h src/cairo-cff-subset.c src/cairo-font-face.c src/cairo-ft-font.c src/cairo-hash.c src/cairo-hash-private.h src/cairo-misc.c src/cairo-ps-surface.c src/cairo-scaled-font.c src/cairo-scaled-font-subsets.c

Chris Wilson ickle at kemper.freedesktop.org
Fri Nov 7 12:52:39 PST 2008


 src/cairo-cache-private.h       |    5 +---
 src/cairo-cache.c               |    8 ++----
 src/cairo-cff-subset.c          |   24 ++++++++------------
 src/cairo-font-face.c           |    9 +++----
 src/cairo-ft-font.c             |    6 ++---
 src/cairo-hash-private.h        |    7 ++---
 src/cairo-hash.c                |   40 ++++++++++++----------------------
 src/cairo-misc.c                |    7 ++---
 src/cairo-ps-surface.c          |    2 -
 src/cairo-scaled-font-subsets.c |   47 +++++++++++++++++++---------------------
 src/cairo-scaled-font.c         |   18 ++++++---------
 11 files changed, 75 insertions(+), 98 deletions(-)

New commits:
commit f1cae5c52a5ee71b7933fca702bb525d98936838
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Nov 7 20:52:08 2008 +0000

    [ps] Trivial compile warning clenaup.
    
    Add a missing const to silence the compiler.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 5dcdce5..9916651 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -1836,7 +1836,7 @@ fail:
 
 static cairo_status_t
 _cairo_ps_surface_emit_base85_string (cairo_ps_surface_t    *surface,
-				      unsigned char	    *data,
+				      const unsigned char   *data,
 				      unsigned long	     length,
 				      cairo_bool_t           use_strings)
 {
commit 2b32c8b9e572c96ce8ba5c7d43b568f18f6da295
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Nov 7 20:30:33 2008 +0000

    [hash] Return lookup entry.
    
    Use the return value to return the result from _cairo_hash_table_lookup()
    (as opposed to filling an output parameter on the stack) as this (a)
    results in cleaner code (no strict-alias breaking pointer casts), (b)
    produces a smaller binary and (c) is measurably faster.

diff --git a/src/cairo-cache-private.h b/src/cairo-cache-private.h
index 4ae63ad..6a9b8b8 100644
--- a/src/cairo-cache-private.h
+++ b/src/cairo-cache-private.h
@@ -109,10 +109,9 @@ _cairo_cache_freeze (cairo_cache_t *cache);
 cairo_private void
 _cairo_cache_thaw (cairo_cache_t *cache);
 
-cairo_private cairo_bool_t
+cairo_private void *
 _cairo_cache_lookup (cairo_cache_t	  *cache,
-		     cairo_cache_entry_t  *key,
-		     cairo_cache_entry_t **entry_return);
+		     cairo_cache_entry_t  *key);
 
 cairo_private cairo_status_t
 _cairo_cache_insert (cairo_cache_t	 *cache,
diff --git a/src/cairo-cache.c b/src/cairo-cache.c
index 1c458df..01e5713 100644
--- a/src/cairo-cache.c
+++ b/src/cairo-cache.c
@@ -222,14 +222,12 @@ _cairo_cache_thaw (cairo_cache_t *cache)
  * @key, (which will now be in *entry_return). %FALSE otherwise, (in
  * which case *entry_return will be %NULL).
  **/
-cairo_bool_t
+void *
 _cairo_cache_lookup (cairo_cache_t	  *cache,
-		     cairo_cache_entry_t  *key,
-		     cairo_cache_entry_t **entry_return)
+		     cairo_cache_entry_t  *key)
 {
     return _cairo_hash_table_lookup (cache->hash_table,
-				     (cairo_hash_entry_t *) key,
-				     (cairo_hash_entry_t **) entry_return);
+				     (cairo_hash_entry_t *) key);
 }
 
 /**
diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c
index 9a4e3d6..45be5d1 100644
--- a/src/cairo-cff-subset.c
+++ b/src/cairo-cff-subset.c
@@ -529,9 +529,8 @@ cff_dict_remove (cairo_hash_table_t *dict, unsigned short operator)
     cff_dict_operator_t key, *op;
 
     _cairo_dict_init_key (&key, operator);
-    if (_cairo_hash_table_lookup (dict, &key.base,
-                                  (cairo_hash_entry_t **) &op))
-    {
+    op = _cairo_hash_table_lookup (dict, &key.base);
+    if (op != NULL) {
         free (op->operand);
         _cairo_hash_table_remove (dict, (cairo_hash_entry_t *) op);
         free (op);
@@ -546,9 +545,8 @@ cff_dict_get_operands (cairo_hash_table_t *dict,
     cff_dict_operator_t key, *op;
 
     _cairo_dict_init_key (&key, operator);
-    if (_cairo_hash_table_lookup (dict, &key.base,
-                                  (cairo_hash_entry_t **) &op))
-    {
+    op = _cairo_hash_table_lookup (dict, &key.base);
+    if (op != NULL) {
         *size = op->operand_length;
         return op->operand;
     }
@@ -566,9 +564,8 @@ cff_dict_set_operands (cairo_hash_table_t *dict,
     cairo_status_t status;
 
     _cairo_dict_init_key (&key, operator);
-    if (_cairo_hash_table_lookup (dict, &key.base,
-                                  (cairo_hash_entry_t **) &op))
-    {
+    op = _cairo_hash_table_lookup (dict, &key.base);
+    if (op != NULL) {
         free (op->operand);
         op->operand = malloc (size);
 	if (op->operand == NULL)
@@ -599,9 +596,8 @@ cff_dict_get_location (cairo_hash_table_t *dict,
     cff_dict_operator_t key, *op;
 
     _cairo_dict_init_key (&key, operator);
-    if (_cairo_hash_table_lookup (dict, &key.base,
-                                  (cairo_hash_entry_t **) &op))
-    {
+    op = _cairo_hash_table_lookup (dict, &key.base);
+    if (op != NULL) {
         *size = op->operand_length;
         return op->operand_offset;
     }
@@ -660,8 +656,8 @@ cff_dict_write (cairo_hash_table_t *dict, cairo_array_t *output)
     /* The CFF specification requires that the Top Dict of CID fonts
      * begin with the ROS operator. */
     _cairo_dict_init_key (&key, ROS_OP);
-    if (_cairo_hash_table_lookup (dict, &key.base,
-                                  (cairo_hash_entry_t **) &op))
+    op = _cairo_hash_table_lookup (dict, &key.base);
+    if (op != NULL)
         cairo_dict_write_operator (op, &write_info);
 
     _cairo_hash_table_foreach (dict, _cairo_dict_collect, &write_info);
diff --git a/src/cairo-font-face.c b/src/cairo-font-face.c
index 6cea395..f9a838a 100644
--- a/src/cairo-font-face.c
+++ b/src/cairo-font-face.c
@@ -499,11 +499,10 @@ cairo_toy_font_face_create (const char          *family,
     _cairo_toy_font_face_init_key (&key, family, slant, weight);
 
     /* Return existing font_face if it exists in the hash table. */
-    if (_cairo_hash_table_lookup (hash_table,
-				  &key.base.hash_entry,
-				  (cairo_hash_entry_t **) &font_face))
-    {
-	if (! font_face->base.status)  {
+    font_face = _cairo_hash_table_lookup (hash_table,
+					  &key.base.hash_entry);
+    if (font_face != NULL) {
+	if (font_face->base.status == CAIRO_STATUS_SUCCESS) {
 	    /* We increment the reference count here manually to avoid
 	       double-locking. */
 	    _cairo_reference_count_inc (&font_face->base.ref_count);
diff --git a/src/cairo-ft-font.c b/src/cairo-ft-font.c
index cd11253..7cae046 100644
--- a/src/cairo-ft-font.c
+++ b/src/cairo-ft-font.c
@@ -422,9 +422,9 @@ _cairo_ft_unscaled_font_create_internal (cairo_bool_t from_face,
     _cairo_ft_unscaled_font_init_key (&key, from_face, filename, id, font_face);
 
     /* Return existing unscaled font if it exists in the hash table. */
-    if (_cairo_hash_table_lookup (font_map->hash_table, &key.base.hash_entry,
-				  (cairo_hash_entry_t **) &unscaled))
-    {
+    unscaled = _cairo_hash_table_lookup (font_map->hash_table,
+					 &key.base.hash_entry);
+    if (unscaled != NULL) {
 	_cairo_unscaled_font_reference (&unscaled->base);
 	_cairo_ft_unscaled_font_map_unlock ();
 	return unscaled;
diff --git a/src/cairo-hash-private.h b/src/cairo-hash-private.h
index 9101f2e..a0be097 100644
--- a/src/cairo-hash-private.h
+++ b/src/cairo-hash-private.h
@@ -63,10 +63,9 @@ _cairo_hash_table_create (cairo_hash_keys_equal_func_t keys_equal);
 cairo_private void
 _cairo_hash_table_destroy (cairo_hash_table_t *hash_table);
 
-cairo_private cairo_bool_t
+cairo_private void *
 _cairo_hash_table_lookup (cairo_hash_table_t  *hash_table,
-			  cairo_hash_entry_t  *key,
-			  cairo_hash_entry_t **entry_return);
+			  cairo_hash_entry_t  *key);
 
 cairo_private void *
 _cairo_hash_table_random_entry (cairo_hash_table_t	   *hash_table,
@@ -81,7 +80,7 @@ _cairo_hash_table_remove (cairo_hash_table_t *hash_table,
 			  cairo_hash_entry_t *key);
 
 cairo_private void
-_cairo_hash_table_foreach (cairo_hash_table_t 	      *hash_table,
+_cairo_hash_table_foreach (cairo_hash_table_t	      *hash_table,
 			   cairo_hash_callback_func_t  hash_callback,
 			   void			      *closure);
 
diff --git a/src/cairo-hash.c b/src/cairo-hash.c
index 41abafd..5b2704f 100644
--- a/src/cairo-hash.c
+++ b/src/cairo-hash.c
@@ -52,12 +52,11 @@
  *       Appears in the table as any non-%NULL, non-DEAD_ENTRY pointer.
  */
 
-static cairo_hash_entry_t dead_entry = { 0 };
-#define DEAD_ENTRY (&dead_entry)
+#define DEAD_ENTRY ((cairo_hash_entry_t *) 0x1)
 
 #define ENTRY_IS_FREE(entry) ((entry) == NULL)
 #define ENTRY_IS_DEAD(entry) ((entry) == DEAD_ENTRY)
-#define ENTRY_IS_LIVE(entry) ((entry) && ! ENTRY_IS_DEAD(entry))
+#define ENTRY_IS_LIVE(entry) ((entry) >  DEAD_ENTRY)
 
 /* We expect keys will not be destroyed frequently, so our table does not
  * contain any explicit shrinking code nor any chain-coalescing code for
@@ -355,32 +354,25 @@ _cairo_hash_table_resize  (cairo_hash_table_t *hash_table)
  * _cairo_hash_table_lookup:
  * @hash_table: a hash table
  * @key: the key of interest
- * @entry_return: pointer for return value.
  *
  * Performs a lookup in @hash_table looking for an entry which has a
  * key that matches @key, (as determined by the keys_equal() function
  * passed to _cairo_hash_table_create).
  *
- * Return value: %TRUE if there is an entry in the hash table that
- * matches the given key, (which will now be in *entry_return). %FALSE
- * otherwise, (in which case *entry_return will be %NULL).
+ * Return value: the matching entry, of %NULL if no match was found.
  **/
-cairo_bool_t
+void *
 _cairo_hash_table_lookup (cairo_hash_table_t *hash_table,
-			  cairo_hash_entry_t *key,
-			  cairo_hash_entry_t **entry_return)
+			  cairo_hash_entry_t *key)
 {
     cairo_hash_entry_t **entry;
 
     /* See if we have an entry in the table already. */
     entry = _cairo_hash_table_lookup_internal (hash_table, key, FALSE);
-    if (ENTRY_IS_LIVE(*entry)) {
-	*entry_return = *entry;
-	return TRUE;
-    }
+    if (ENTRY_IS_LIVE (*entry))
+	return *entry;
 
-    *entry_return = NULL;
-    return FALSE;
+    return NULL;
 }
 
 /**
diff --git a/src/cairo-misc.c b/src/cairo-misc.c
index 667fa52..5d258ff 100644
--- a/src/cairo-misc.c
+++ b/src/cairo-misc.c
@@ -717,10 +717,9 @@ _cairo_intern_string (const char **str_inout, int len)
     if (_cairo_intern_string_ht == NULL)
 	_cairo_intern_string_ht = _cairo_hash_table_create (_intern_string_equal);
 
-    if (! _cairo_hash_table_lookup (_cairo_intern_string_ht,
-				    &tmpl.hash_entry,
-				    (cairo_hash_entry_t **) &istring))
-    {
+    istring = _cairo_hash_table_lookup (_cairo_intern_string_ht,
+					&tmpl.hash_entry);
+    if (istring == NULL) {
 	istring = malloc (sizeof (cairo_intern_string_t) + len + 1);
 	if (istring != NULL) {
 	    istring->hash_entry.hash = tmpl.hash_entry.hash;
diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index 815c4d8..7ec2a2d 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -420,9 +420,9 @@ _cairo_sub_font_lookup_glyph (cairo_sub_font_t	                *sub_font,
     cairo_sub_font_glyph_t key, *sub_font_glyph;
 
     _cairo_sub_font_glyph_init_key (&key, scaled_font_glyph_index);
-    if (_cairo_hash_table_lookup (sub_font->sub_font_glyphs, &key.base,
-				    (cairo_hash_entry_t **) &sub_font_glyph))
-    {
+    sub_font_glyph = _cairo_hash_table_lookup (sub_font->sub_font_glyphs,
+					      &key.base);
+    if (sub_font_glyph != NULL) {
         subset_glyph->font_id = sub_font->font_id;
         subset_glyph->subset_id = sub_font_glyph->subset_id;
         subset_glyph->subset_glyph_index = sub_font_glyph->subset_glyph_index;
@@ -450,9 +450,9 @@ _cairo_sub_font_map_glyph (cairo_sub_font_t	*sub_font,
     cairo_status_t status;
 
     _cairo_sub_font_glyph_init_key (&key, scaled_font_glyph_index);
-    if (! _cairo_hash_table_lookup (sub_font->sub_font_glyphs, &key.base,
-				    (cairo_hash_entry_t **) &sub_font_glyph))
-    {
+    sub_font_glyph = _cairo_hash_table_lookup (sub_font->sub_font_glyphs,
+					       &key.base);
+    if (sub_font_glyph == NULL) {
 	cairo_scaled_glyph_t *scaled_glyph;
 
 	if (sub_font->num_glyphs_in_current_subset == sub_font->max_glyphs_per_subset)
@@ -679,9 +679,9 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*subsets,
     if (subsets->type != CAIRO_SUBSETS_SCALED) {
         key.is_scaled = FALSE;
         _cairo_sub_font_init_key (&key, scaled_font);
-        if (_cairo_hash_table_lookup (subsets->unscaled_sub_fonts, &key.base,
-                                        (cairo_hash_entry_t **) &sub_font))
-        {
+	sub_font = _cairo_hash_table_lookup (subsets->unscaled_sub_fonts,
+					     &key.base);
+        if (sub_font != NULL) {
             if (_cairo_sub_font_lookup_glyph (sub_font,
                                               scaled_font_glyph_index,
 					      utf8, utf8_len,
@@ -693,9 +693,9 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*subsets,
     /* Lookup glyph in scaled subsets */
     key.is_scaled = TRUE;
     _cairo_sub_font_init_key (&key, scaled_font);
-    if (_cairo_hash_table_lookup (subsets->scaled_sub_fonts, &key.base,
-                                  (cairo_hash_entry_t **) &sub_font))
-    {
+    sub_font = _cairo_hash_table_lookup (subsets->scaled_sub_fonts,
+					 &key.base);
+    if (sub_font != NULL) {
         if (_cairo_sub_font_lookup_glyph (sub_font,
                                           scaled_font_glyph_index,
 					  utf8, utf8_len,
@@ -732,9 +732,9 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*subsets,
         /* Path available. Add to unscaled subset. */
         key.is_scaled = FALSE;
         _cairo_sub_font_init_key (&key, scaled_font);
-        if (! _cairo_hash_table_lookup (subsets->unscaled_sub_fonts, &key.base,
-                                        (cairo_hash_entry_t **) &sub_font))
-        {
+	sub_font = _cairo_hash_table_lookup (subsets->unscaled_sub_fonts,
+					     &key.base);
+        if (sub_font == NULL) {
             font_face = cairo_scaled_font_get_font_face (scaled_font);
             cairo_matrix_init_identity (&identity);
             _cairo_font_options_init_default (&font_options);
@@ -791,9 +791,9 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*subsets,
         /* No path available. Add to scaled subset. */
         key.is_scaled = TRUE;
         _cairo_sub_font_init_key (&key, scaled_font);
-        if (! _cairo_hash_table_lookup (subsets->scaled_sub_fonts, &key.base,
-                                        (cairo_hash_entry_t **) &sub_font))
-        {
+	sub_font = _cairo_hash_table_lookup (subsets->scaled_sub_fonts,
+					     &key.base);
+        if (sub_font == NULL) {
             subset_glyph->is_scaled = TRUE;
             subset_glyph->is_composite = FALSE;
             if (subsets->type == CAIRO_SUBSETS_SCALED)
@@ -1018,14 +1018,13 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
 	}
 
 	if (utf16_len == 1) {
-	    snprintf (buf, sizeof(buf), "uni%04X", (int)(utf16[0]));
+	    snprintf (buf, sizeof (buf), "uni%04X", (int) utf16[0]);
 	    _cairo_string_init_key (&key, buf);
-	    if (_cairo_hash_table_lookup (names, &key.base,
-					  (cairo_hash_entry_t **) &entry)) {
-		snprintf (buf, sizeof(buf), "g%d", i);
-	    }
+	    entry = _cairo_hash_table_lookup (names, &key.base);
+	    if (entry != NULL)
+		snprintf (buf, sizeof (buf), "g%d", i);
 	} else {
-	    snprintf (buf, sizeof(buf), "g%d", i);
+	    snprintf (buf, sizeof (buf), "g%d", i);
 	}
 	if (utf16)
 	    free (utf16);
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index bfeeaf6..af217c6 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -465,14 +465,13 @@ void
 _cairo_scaled_font_unregister_placeholder_and_lock_font_map (cairo_scaled_font_t *scaled_font)
 {
     cairo_scaled_font_t *placeholder_scaled_font;
-    cairo_bool_t found;
 
     CAIRO_MUTEX_LOCK (_cairo_scaled_font_map_mutex);
 
-    found = _cairo_hash_table_lookup (cairo_scaled_font_map->hash_table,
-				      &scaled_font->hash_entry,
-				      (cairo_hash_entry_t**) &placeholder_scaled_font);
-    assert (found);
+    placeholder_scaled_font =
+	_cairo_hash_table_lookup (cairo_scaled_font_map->hash_table,
+				  &scaled_font->hash_entry);
+    assert (placeholder_scaled_font != NULL);
     assert (placeholder_scaled_font->placeholder);
     assert (CAIRO_MUTEX_IS_LOCKED (placeholder_scaled_font->mutex));
 
@@ -823,8 +822,8 @@ cairo_scaled_font_create (cairo_font_face_t          *font_face,
     }
     else
     {
-	while (_cairo_hash_table_lookup (font_map->hash_table, &key.hash_entry,
-					 (cairo_hash_entry_t**) &scaled_font))
+	while ((scaled_font = _cairo_hash_table_lookup (font_map->hash_table,
+							&key.hash_entry)))
 	{
 	    if (! scaled_font->placeholder)
 		break;
@@ -2348,9 +2347,8 @@ _cairo_scaled_glyph_lookup (cairo_scaled_font_t *scaled_font,
      * Check cache for glyph
      */
     info |= CAIRO_SCALED_GLYPH_INFO_METRICS;
-    if (!_cairo_cache_lookup (scaled_font->glyphs, &key,
-			      (cairo_cache_entry_t **) &scaled_glyph))
-    {
+    scaled_glyph = _cairo_cache_lookup (scaled_font->glyphs, &key);
+    if (scaled_glyph == NULL) {
 	/*
 	 * On miss, create glyph and insert into cache
 	 */
commit d15fb9344bf86dd52cda0b43d3dfc49397fd84ec
Author: Karl Tomlinson <karlt+ at karlt.net>
Date:   Fri Nov 7 20:06:35 2008 +0000

    [hash] Set is_unique when finding an available for inserts
    
    As we obey the rule in Cairo that we only insert if we know that there is
    no existing entry in the hash table, we can therefore perform a much quicker
    search knowing that the key is unique.

diff --git a/src/cairo-hash.c b/src/cairo-hash.c
index 2317eb1..41abafd 100644
--- a/src/cairo-hash.c
+++ b/src/cairo-hash.c
@@ -448,8 +448,8 @@ _cairo_hash_table_random_entry (cairo_hash_table_t	   *hash_table,
  *
  * Insert the entry #key_and_value into the hash table.
  *
- * WARNING: It is a fatal error if an entry exists in the hash table
- * with a matching key, (this function will halt).
+ * WARNING: There must not be an existing entry in the hash table
+ * with a matching key.
  *
  * WARNING: It is a fatal error to insert an element while
  * an iterator is running
@@ -472,13 +472,11 @@ _cairo_hash_table_insert (cairo_hash_table_t *hash_table,
     assert (hash_table->iterating == 0);
 
     entry = _cairo_hash_table_lookup_internal (hash_table,
-					       key_and_value, FALSE);
-
-    if (ENTRY_IS_LIVE(*entry))
-    {
-	/* User is being bad, let's crash. */
-	ASSERT_NOT_REACHED;
-    }
+					       key_and_value,
+					       TRUE);
+    /* _cairo_hash_table_lookup_internal with key_unique = TRUE
+     * aways returns an available entry. */
+    assert (! ENTRY_IS_LIVE(*entry));
 
     *entry = key_and_value;
     hash_table->live_entries++;


More information about the cairo-commit mailing list