summaryrefslogtreecommitdiff
path: root/src/cairo-hash.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2008-11-07 20:30:33 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2008-11-07 20:50:34 +0000
commit2b32c8b9e572c96ce8ba5c7d43b568f18f6da295 (patch)
tree5bbac3fa688087fb74d3598105dd50786c68816c /src/cairo-hash.c
parentd15fb9344bf86dd52cda0b43d3dfc49397fd84ec (diff)
downloadcairo-2b32c8b9e572c96ce8ba5c7d43b568f18f6da295.tar.gz
[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.
Diffstat (limited to 'src/cairo-hash.c')
-rw-r--r--src/cairo-hash.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/cairo-hash.c b/src/cairo-hash.c
index 41abafd6e..5b2704f2e 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;
}
/**