aboutsummaryrefslogtreecommitdiff
path: root/hash.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-03-21 14:02:19 -0700
committerJunio C Hamano <gitster@pobox.com>2013-03-21 14:02:19 -0700
commitc241e285e53bc84def85682eeaa265c1cd99cceb (patch)
tree149c957fa2d297c1a2ddb07e5b459f855eb831d5 /hash.h
parent09386fff3370c1833cc8c3ba8bbf70e460fecf17 (diff)
parentc73592812d36ccc7eccfd0489177970d246fa522 (diff)
downloadgit-c241e285e53bc84def85682eeaa265c1cd99cceb.tar.xz
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
Diffstat (limited to 'hash.h')
-rw-r--r--hash.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/hash.h b/hash.h
index b875ce67c4..1d43ac0ba0 100644
--- a/hash.h
+++ b/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