mirror of
https://github.com/git/git
synced 2024-08-24 18:26:02 +00:00
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
This commit is contained in:
commit
c241e285e5
|
@ -389,6 +389,7 @@ static int find_exact_renames(struct diff_options *options)
|
||||||
struct hash_table file_table;
|
struct hash_table file_table;
|
||||||
|
|
||||||
init_hash(&file_table);
|
init_hash(&file_table);
|
||||||
|
preallocate_hash(&file_table, rename_src_nr + rename_dst_nr);
|
||||||
for (i = 0; i < rename_src_nr; i++)
|
for (i = 0; i < rename_src_nr; i++)
|
||||||
insert_file_table(&file_table, -1, i, rename_src[i].p->one);
|
insert_file_table(&file_table, -1, i, rename_src[i].p->one);
|
||||||
|
|
||||||
|
|
7
hash.h
7
hash.h
|
@ -40,4 +40,11 @@ static inline void init_hash(struct hash_table *table)
|
||||||
table->array = NULL;
|
table->array = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void preallocate_hash(struct hash_table *table, unsigned int elts)
|
||||||
|
{
|
||||||
|
assert(table->size == 0 && table->nr == 0 && table->array == NULL);
|
||||||
|
table->size = elts * 2;
|
||||||
|
table->array = xcalloc(sizeof(struct hash_table_entry), table->size);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -92,6 +92,8 @@ static void lazy_init_name_hash(struct index_state *istate)
|
||||||
|
|
||||||
if (istate->name_hash_initialized)
|
if (istate->name_hash_initialized)
|
||||||
return;
|
return;
|
||||||
|
if (istate->cache_nr)
|
||||||
|
preallocate_hash(&istate->name_hash, istate->cache_nr);
|
||||||
for (nr = 0; nr < istate->cache_nr; nr++)
|
for (nr = 0; nr < istate->cache_nr; nr++)
|
||||||
hash_index_entry(istate, istate->cache[nr]);
|
hash_index_entry(istate, istate->cache[nr]);
|
||||||
istate->name_hash_initialized = 1;
|
istate->name_hash_initialized = 1;
|
||||||
|
|
Loading…
Reference in a new issue