Skip to content

Commit 23da3cc

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 569be14 commit 23da3cc

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
@@ -80,6 +80,18 @@ static struct diff_rename_src *locate_rename_src(struct diff_filespec *one,
8080

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

108+
append_it:
96109
if (!insert_ok)
97110
return NULL;
98111

0 commit comments

Comments
 (0)