Skip to content

Commit 028af71

Browse files
jeffhostetlerdscho
authored andcommitted
diffcore-rename: speed up register_rename_src
Teach register_rename_src() to see if new file pair can simply be appended to the rename_src[] array before performing the binary search to find the proper insertion point. This is a performance optimization. This routine is called during run_diff_files in status and the caller is iterating over the sorted index, so we should expect to be able to append in the normal case. The existing insert logic is preserved so we don't have to assume that, but simply take advantage of it if possible. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
1 parent fc4dfd4 commit 028af71

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

diffcore-rename.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
8181

8282
first = 0;
8383
last = rename_src_nr;
84+
85+
if (last > 0) {
86+
struct diff_rename_src *src = &(rename_src[last-1]);
87+
int cmp = strcmp(one->path, src->p->one->path);
88+
if (!cmp)
89+
return src;
90+
if (cmp > 0) {
91+
first = last;
92+
goto append_it;
93+
}
94+
}
95+
8496
while (last > first) {
8597
int next = (last + first) >> 1;
8698
struct diff_rename_src *src = &(rename_src[next]);
@@ -94,6 +106,7 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
94106
first = next+1;
95107
}
96108

109+
append_it:
97110
/* insert to make it at "first" */
98111
ALLOC_GROW(rename_src, rename_src_nr + 1, rename_src_alloc);
99112
rename_src_nr++;

0 commit comments

Comments
 (0)