From a80bcc50853500f3213a9a24c0752057e3c49b7c Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Mon, 14 Feb 2011 16:44:56 -0800 Subject: Recover bad performance of 0-keyed tables. We do this by special-casing the (unusual) zero case and only bother checking the is_empty bit in the zero case. --- src/upb_table.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/upb_table.h b/src/upb_table.h index e667f0d..b173101 100644 --- a/src/upb_table.h +++ b/src/upb_table.h @@ -101,12 +101,21 @@ INLINE uint32_t upb_inttable_bucket(upb_inttable *t, upb_inttable_key_t k) { INLINE void *upb_inttable_fastlookup(upb_inttable *t, uint32_t key, uint32_t entry_size) { uint32_t bucket = upb_inttable_bucket(t, key); - upb_inttable_entry *e; - do { - e = (upb_inttable_entry*)UPB_INDEX(t->t.entries, bucket-1, entry_size); - if(e->key == key && e->has_entry) return e; - } while((bucket = e->next) != UPB_END_OF_CHAIN); - return NULL; /* Not found. */ + upb_inttable_entry *e = + (upb_inttable_entry*)UPB_INDEX(t->t.entries, bucket-1, entry_size); + if (key == 0) { + while (1) { + if (e->key == 0 && e->has_entry) return e; + if ((bucket = e->next) == UPB_END_OF_CHAIN) return NULL; + e = (upb_inttable_entry*)UPB_INDEX(t->t.entries, bucket-1, entry_size); + } + } else { + while (1) { + if (e->key == key) return e; + if ((bucket = e->next) == UPB_END_OF_CHAIN) return NULL; + e = (upb_inttable_entry*)UPB_INDEX(t->t.entries, bucket-1, entry_size); + } + } } INLINE void *upb_inttable_lookup(upb_inttable *t, uint32_t key) { -- cgit v1.2.3