mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
Preallocate hash tables when the number of inserts are known in advance
This avoids unnecessary re-allocations and reinsertions. On webkit.git (i.e. about 182k inserts to the name hash table), this reduces about 100ms out of 3s user time. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
03a0fb0ccf
commit
c73592812d
7
hash.h
7
hash.h
@@ -40,4 +40,11 @@ static inline void init_hash(struct hash_table *table)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user