summaryrefslogtreecommitdiff
path: root/src/index.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2015-12-16 17:00:25 +0100
committerVicent Marti <tanoku@gmail.com>2015-12-16 17:04:08 +0100
commitd7d46cfbfd19983ee71b53607abcaf55872be83a (patch)
treef6ad3bde9a6aa3062ce3ac1b3d39b9a87a4a8d49 /src/index.c
parent0cc20a8c487cae629ea269fec3173f5647c38d0c (diff)
downloadlibgit2-d7d46cfbfd19983ee71b53607abcaf55872be83a.tar.gz
index: Preallocate the entries vector with size hint
Diffstat (limited to 'src/index.c')
-rw-r--r--src/index.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/index.c b/src/index.c
index 04acd4f04..03873f427 100644
--- a/src/index.c
+++ b/src/index.c
@@ -1556,11 +1556,19 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
assert(index);
+ if (!source_entries->length)
+ return 0;
+
if (git_mutex_lock(&index->lock) < 0) {
giterr_set(GITERR_OS, "Unable to acquire index lock");
return -1;
}
+ if (git_vector_size_hint(&index->entries, source_entries->length) < 0) {
+ git_mutex_unlock(&index->lock);
+ return -1;
+ }
+
git_vector_foreach(source_entries, i, source_entry) {
git_index_entry *entry = NULL;