Commit ef8b7febc5624c265201400001e3d654dea96d83

Vicent Marti 2015-12-16T19:36:50

index: Also size-hint the hash table Note that we're not checking whether the resize succeeds; in OOM cases, we let it run with a "small" vector and hash table and see if by chance we can grow it dynamically as we insert the new entries. Nothing to lose really.

diff --git a/src/idxmap.h b/src/idxmap.h
index 74304bb..4122a89 100644
--- a/src/idxmap.h
+++ b/src/idxmap.h
@@ -70,6 +70,7 @@ static kh_inline khint_t idxentry_hash(const git_index_entry *e)
 #define git_idxmap_valid_index(h, idx) (idx != kh_end(h))
 #define git_idxmap_has_data(h, idx) kh_exist(h, idx)
 
+#define git_idxmap_resize(h,s)  kh_resize(idx, h, s)
 #define git_idxmap_free(h)  kh_destroy(idx, h), h = NULL
 #define git_idxmap_clear(h) kh_clear(idx, h)
 
diff --git a/src/index.c b/src/index.c
index 03873f4..5c7bd90 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1564,10 +1564,8 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
 		return -1;
 	}
 
-	if (git_vector_size_hint(&index->entries, source_entries->length) < 0) {
-		git_mutex_unlock(&index->lock);
-		return -1;
-	}
+	git_vector_size_hint(&index->entries, source_entries->length);
+	git_idxmap_resize(index->entries_map, source_entries->length * 1.3);
 
 	git_vector_foreach(source_entries, i, source_entry) {
 		git_index_entry *entry = NULL;