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 <>
 diffcore-pickaxe.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c
index 26ddf00..bfaabab 100644
--- a/diffcore-pickaxe.c
+++ b/diffcore-pickaxe.c
@@ -83,7 +83,7 @@ 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)) {
@@ -91,6 +91,9 @@ static int diff_grep(struct diff_filepair *p, struct 
diff_options *o,
                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);
@@ -125,6 +128,8 @@ static int diff_grep(struct diff_filepair *p, struct 
diff_options *o,
        if (textconv_two)
+       diff_free_filespec_data(p->one);
+       diff_free_filespec_data(p->two);
        return hit;

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to