From: Junio C Hamano Date: Thu, 21 Mar 2013 21:02:19 +0000 (-0700) Subject: Merge branch 'nd/preallocate-hash' X-Git-Tag: v1.8.3-rc0~207 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/c241e285e53bc84def85682eeaa265c1cd99cceb?ds=inline;hp=-c Merge branch 'nd/preallocate-hash' 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 --- c241e285e53bc84def85682eeaa265c1cd99cceb diff --combined name-hash.c index 942c459622,2a1f108247..9bac31a6ab --- a/name-hash.c +++ b/name-hash.c @@@ -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;