Makefile: fix default regex settings on Darwin
[gitweb.git] / name-hash.c
index 91241336f827090848a019990253e20725ff62cb..617c86c53762575373d0bcbf3d8bab09cb042caa 100644 (file)
@@ -24,11 +24,11 @@ static unsigned int hash_name(const char *name, int namelen)
 {
        unsigned int hash = 0x123;
 
-       do {
+       while (namelen--) {
                unsigned char c = *name++;
                c = icase_hash(c);
                hash = hash*101 + c;
-       } while (--namelen);
+       }
        return hash;
 }
 
@@ -150,6 +150,8 @@ static void lazy_init_name_hash(struct index_state *istate)
 
        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;