Branch: Tag:

2014-12-04

2014-12-04 19:26:33 by Arne Goedeke <el@laramies.com>

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.

26:   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;    }    }