Skip to content

Commit

Permalink
diffcore-pickaxe: remove unnecessary call to get_textconv()
Browse files Browse the repository at this point in the history
The fill_one() function is responsible for finding and filling the
textconv filter as necessary, and is called by diff_grep() function
that implements "git log -G<pattern>".

The has_changes() function that implements "git log -S<block>" calls
get_textconv() for two sides being compared, before it checks to see
if it was asked to perform the pickaxe limiting.  Move the code
around to avoid this wastage.

After has_changes() calls get_textconv() to obtain textconv for both
sides, fill_one() is called to use them.

By adding get_textconv() to diff_grep() and relieving fill_one() of
responsibility to find the textconv filter, we can avoid calling
get_textconv() twice in has_changes().

With this change it's also no longer necessary for fill_one() to
modify the textconv argument, therefore pass a pointer instead of a
pointer to a pointer.

Signed-off-by: Simon Ruderich <simon@ruderich.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Simon Ruderich authored and Junio C Hamano committed Apr 5, 2013
1 parent ef90ab6 commit bc61589
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions diffcore-pickaxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ static void diffgrep_consume(void *priv, char *line, unsigned long len)
}

static void fill_one(struct diff_filespec *one,
mmfile_t *mf, struct userdiff_driver **textconv)
mmfile_t *mf, struct userdiff_driver *textconv)
{
if (DIFF_FILE_VALID(one)) {
*textconv = get_textconv(one);
mf->size = fill_textconv(*textconv, one, &mf->ptr);
mf->size = fill_textconv(textconv, one, &mf->ptr);
} else {
memset(mf, 0, sizeof(*mf));
}
Expand All @@ -97,8 +96,11 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
if (diff_unmodified_pair(p))
return 0;

fill_one(p->one, &mf1, &textconv_one);
fill_one(p->two, &mf2, &textconv_two);
textconv_one = get_textconv(p->one);
textconv_two = get_textconv(p->two);

fill_one(p->one, &mf1, textconv_one);
fill_one(p->two, &mf2, textconv_two);

if (!mf1.ptr) {
if (!mf2.ptr)
Expand Down Expand Up @@ -201,14 +203,17 @@ static unsigned int contains(mmfile_t *mf, struct diff_options *o,
static int has_changes(struct diff_filepair *p, struct diff_options *o,
regex_t *regexp, kwset_t kws)
{
struct userdiff_driver *textconv_one = get_textconv(p->one);
struct userdiff_driver *textconv_two = get_textconv(p->two);
struct userdiff_driver *textconv_one = NULL;
struct userdiff_driver *textconv_two = NULL;
mmfile_t mf1, mf2;
int ret;

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

textconv_one = get_textconv(p->one);
textconv_two = get_textconv(p->two);

/*
* If we have an unmodified pair, we know that the count will be the
* same and don't even have to load the blobs. Unless textconv is in
Expand All @@ -219,8 +224,8 @@ static int has_changes(struct diff_filepair *p, struct diff_options *o,
if (textconv_one == textconv_two && diff_unmodified_pair(p))
return 0;

fill_one(p->one, &mf1, &textconv_one);
fill_one(p->two, &mf2, &textconv_two);
fill_one(p->one, &mf1, textconv_one);
fill_one(p->two, &mf2, textconv_two);

if (!mf1.ptr) {
if (!mf2.ptr)
Expand Down

0 comments on commit bc61589

Please sign in to comment.