Skip to content

Commit ef8b7fe

Browse files
committed
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.
1 parent d7d46cf commit ef8b7fe

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/idxmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static kh_inline khint_t idxentry_hash(const git_index_entry *e)
7070
#define git_idxmap_valid_index(h, idx) (idx != kh_end(h))
7171
#define git_idxmap_has_data(h, idx) kh_exist(h, idx)
7272

73+
#define git_idxmap_resize(h,s) kh_resize(idx, h, s)
7374
#define git_idxmap_free(h) kh_destroy(idx, h), h = NULL
7475
#define git_idxmap_clear(h) kh_clear(idx, h)
7576

src/index.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,10 +1564,8 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
15641564
return -1;
15651565
}
15661566

1567-
if (git_vector_size_hint(&index->entries, source_entries->length) < 0) {
1568-
git_mutex_unlock(&index->lock);
1569-
return -1;
1570-
}
1567+
git_vector_size_hint(&index->entries, source_entries->length);
1568+
git_idxmap_resize(index->entries_map, source_entries->length * 1.3);
15711569

15721570
git_vector_foreach(source_entries, i, source_entry) {
15731571
git_index_entry *entry = NULL;

0 commit comments

Comments
 (0)