From 8ac435301605ddbda81c48ddbaaa59f82c59adcf Mon Sep 17 00:00:00 2001 From: Arne Goedeke <el@laramies.com> Date: Fri, 30 May 2014 13:41:36 +0200 Subject: [PATCH] hashtable.c: do not rechain in lookup Reordering the bucket list during lookup is very expensive. Removing it makes cpp() about 10% faster on a file that only contains define and if defined() statements. Additionally, the const attribute on the hash table argument is correct now. --- src/hashtable.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/hashtable.c b/src/hashtable.c index f9b0d96d75..c7fc06a8b1 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -26,20 +26,14 @@ static size_t gobble(const struct pike_string *s) struct hash_entry *hash_lookup(const struct hash_table *h, const struct pike_string *s) { - struct hash_entry *e, **prev, **base; + struct hash_entry *e; if(!h) return 0; - base = prev = h->htable + (gobble(s) & h->mask); - for( ;(e = *prev); prev= &e->next) + e = h->htable[gobble(s) & h->mask]; + for( ; e; e = e->next) { if(s == e->s) { - /* Teleport entry to beginning of line */ - *prev = e->next; - e->next = *base; - *base = e; - /* Entry arrives in a puff of smoke. */ - return e; } } -- GitLab