Merge branch 'nd/preallocate-hash'
authorJunio C Hamano <gitster@pobox.com>
Thu, 21 Mar 2013 21:02:19 +0000 (14:02 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Mar 2013 21:02:19 +0000 (14:02 -0700)
When we know approximately how many entries we will have in the
hash-table, it makes sense to size the hash table to that number
from the beginning to avoid unnecessary rehashing.

* nd/preallocate-hash:
Preallocate hash tables when the number of inserts are known in advance

1  2 
name-hash.c
diff --combined name-hash.c
index 942c45962252eba4c6f88b4f4f7593c9247749ae,2a1f1082470a286dc32e84e74f44da14077296a9..9bac31a6ab7aa80586828e7f48ab829e5b77a740
@@@ -24,11 -24,11 +24,11 @@@ static unsigned int hash_name(const cha
  {
        unsigned int hash = 0x123;
  
 -      do {
 +      while (namelen--) {
                unsigned char c = *name++;
                c = icase_hash(c);
                hash = hash*101 + c;
 -      } while (--namelen);
 +      }
        return hash;
  }
  
@@@ -92,6 -92,8 +92,8 @@@ static void lazy_init_name_hash(struct 
  
        if (istate->name_hash_initialized)
                return;
+       if (istate->cache_nr)
+               preallocate_hash(&istate->name_hash, istate->cache_nr);
        for (nr = 0; nr < istate->cache_nr; nr++)
                hash_index_entry(istate, istate->cache[nr]);
        istate->name_hash_initialized = 1;