Skip to content

Commit ebb7226

Browse files
committed
diffcore-pickaxe: port optimization from has_changes() to diff_grep()
These two functions are called in the same codeflow to implement "log -S<block>" and "log -G<pattern>", respectively, but the latter lacked two obvious optimizations the former implemented, namely: - When a pickaxe limit is not given at all, they should return without wasting any cycle; - When both sides of the filepair are the same, and the same textconv conversion apply to them, return early, as there will be no interesting differences between the two anyway. Also release the filespec data once the processing is done (this is not about leaking memory--it is about releasing data we finished looking at as early as possible). Signed-off-by: Junio C Hamano <[email protected]>
1 parent a8f6109 commit ebb7226

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

diffcore-pickaxe.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
8383
mmfile_t mf1, mf2;
8484
int hit;
8585

86-
if (diff_unmodified_pair(p))
86+
if (!o->pickaxe[0])
8787
return 0;
8888

8989
if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) {
9090
textconv_one = get_textconv(p->one);
9191
textconv_two = get_textconv(p->two);
9292
}
9393

94+
if (textconv_one == textconv_two && diff_unmodified_pair(p))
95+
return 0;
96+
9497
mf1.size = fill_textconv(textconv_one, p->one, &mf1.ptr);
9598
mf2.size = fill_textconv(textconv_two, p->two, &mf2.ptr);
9699

@@ -125,6 +128,8 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
125128
free(mf1.ptr);
126129
if (textconv_two)
127130
free(mf2.ptr);
131+
diff_free_filespec_data(p->one);
132+
diff_free_filespec_data(p->two);
128133
return hit;
129134
}
130135

0 commit comments

Comments
 (0)