summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2017-04-19 17:06:16 +0000
committerJunio C Hamano <gitster@pobox.com>2017-04-19 20:33:01 -0700
commite5494631ed94017da862d55eb6393a0d01d8b91d (patch)
tree82c6594b2b7203bd72c63a33fa243becafd27236 /read-cache.c
parent350d8701437f2d5031513bb45f1d14545d5a8911 (diff)
downloadgit-e5494631ed94017da862d55eb6393a0d01d8b91d.tar.gz
read-cache: speed up add_index_entry during checkout
Teach add_index_entry_with_check() to see if the path of the new item is greater than the last path in the index array before attempting to search for it. During checkout, merge_working_tree() populates the new index in sorted order, so this change will save a binary lookups per file. This preserves the original behavior but simply checks the last element before starting the search. This helps performance on very large repositories. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/read-cache.c b/read-cache.c
index 11823f5dbc..836338b3ba 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1021,7 +1021,16 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
if (!(option & ADD_CACHE_KEEP_CACHE_TREE))
cache_tree_invalidate_path(istate, ce->name);
- pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
+
+ /*
+ * If this entry's path sorts after the last entry in the index,
+ * we can avoid searching for it.
+ */
+ if (istate->cache_nr > 0 &&
+ strcmp(ce->name, istate->cache[istate->cache_nr - 1]->name) > 0)
+ pos = -istate->cache_nr - 1;
+ else
+ pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce));
/* existing match? Just replace it. */
if (pos >= 0) {