diff options
author | Joshua Haberman <joshua@reverberate.org> | 2011-02-14 16:44:56 -0800 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2011-02-14 16:44:56 -0800 |
commit | a80bcc50853500f3213a9a24c0752057e3c49b7c (patch) | |
tree | 743ad5880fa9a836fc24e06107889c5f98ea7716 /src/upb_table.h | |
parent | 5137ac8d611def74ae493fc5cae989d510bca7ad (diff) |
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.
Diffstat (limited to 'src/upb_table.h')
-rw-r--r-- | src/upb_table.h | 21 |
1 files changed, 15 insertions, 6 deletions
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) { |