Skip to content

Commit

Permalink
diffcore-pickaxe: port optimization from has_changes() to diff_grep()
Browse files Browse the repository at this point in the history
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 <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Apr 5, 2013
1 parent a8f6109 commit ebb7226
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion diffcore-pickaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
mmfile_t mf1, mf2;
int hit;

if (diff_unmodified_pair(p))
if (!o->pickaxe[0])
return 0;

if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) {
textconv_one = get_textconv(p->one);
textconv_two = get_textconv(p->two);
}

if (textconv_one == textconv_two && diff_unmodified_pair(p))
return 0;

mf1.size = fill_textconv(textconv_one, p->one, &mf1.ptr);
mf2.size = fill_textconv(textconv_two, p->two, &mf2.ptr);

Expand Down Expand Up @@ -125,6 +128,8 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
free(mf1.ptr);
if (textconv_two)
free(mf2.ptr);
diff_free_filespec_data(p->one);
diff_free_filespec_data(p->two);
return hit;
}

Expand Down

0 comments on commit ebb7226

Please sign in to comment.