Skip to content

Commit f625b54

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 <[email protected]>
1 parent a41b4ce commit f625b54

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

8585
first = 0;
8686
last = rename_src_nr;
87+
88+
if (last > 0) {
89+
struct diff_rename_src *src = &(rename_src[last-1]);
90+
int cmp = strcmp(one->path, src->p->one->path);
91+
if (!cmp)
92+
return src;
93+
if (cmp > 0) {
94+
first = last;
95+
goto append_it;
96+
}
97+
}
98+
8799
while (last > first) {
88100
int next = first + ((last - first) >> 1);
89101
struct diff_rename_src *src = &(rename_src[next]);
@@ -97,6 +109,7 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
97109
first = next+1;
98110
}
99111

112+
append_it:
100113
/* insert to make it at "first" */
101114
ALLOC_GROW(rename_src, rename_src_nr + 1, rename_src_alloc);
102115
rename_src_nr++;

0 commit comments

Comments
 (0)