Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/hash.h
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-03-17 07:28:06 +0400
committerJunio C Hamano <gitster@pobox.com>2013-03-17 09:57:29 +0400
commitc73592812d36ccc7eccfd0489177970d246fa522 (patch)
tree1e92b0c8fb8cb4bf5bbb10f38cf695785457b2e7 /hash.h
parent03a0fb0ccf48c831060c2243f830b6a12cd8fdf3 (diff)
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>
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