Skip to content

Commit 98cc723

Browse files
jeffhostetlerGit for Windows Build Agent
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 <[email protected]>
1 parent aa80dfb commit 98cc723

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
@@ -82,6 +82,18 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
8282

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

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

0 commit comments

Comments
 (0)