Commit d7d46cfb by Vicent Marti

index: Preallocate the entries vector with size hint

parent 0cc20a8c
......@@ -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;
......
......@@ -40,6 +40,13 @@ GIT_INLINE(int) resize_vector(git_vector *v, size_t new_size)
return 0;
}
int git_vector_size_hint(git_vector *v, size_t size_hint)
{
if (v->_alloc_size >= size_hint)
return 0;
return resize_vector(v, size_hint);
}
int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp)
{
size_t bytes;
......
......@@ -32,6 +32,7 @@ void git_vector_free_deep(git_vector *v); /* free each entry and self */
void git_vector_clear(git_vector *v);
int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp);
void git_vector_swap(git_vector *a, git_vector *b);
int git_vector_size_hint(git_vector *v, size_t size_hint);
void **git_vector_detach(size_t *size, size_t *asize, git_vector *v);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment