Skip to content

Commit bc61589

Browse files
rudisgitster
authored andcommitted
diffcore-pickaxe: remove unnecessary call to get_textconv()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ef90ab6 commit bc61589

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

diffcore-pickaxe.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,10 @@ static void diffgrep_consume(void *priv, char *line, unsigned long len)
7575
}
7676

7777
static void fill_one(struct diff_filespec *one,
78-
mmfile_t *mf, struct userdiff_driver **textconv)
78+
mmfile_t *mf, struct userdiff_driver *textconv)
7979
{
8080
if (DIFF_FILE_VALID(one)) {
81-
*textconv = get_textconv(one);
82-
mf->size = fill_textconv(*textconv, one, &mf->ptr);
81+
mf->size = fill_textconv(textconv, one, &mf->ptr);
8382
} else {
8483
memset(mf, 0, sizeof(*mf));
8584
}
@@ -97,8 +96,11 @@ static int diff_grep(struct diff_filepair *p, struct diff_options *o,
9796
if (diff_unmodified_pair(p))
9897
return 0;
9998

100-
fill_one(p->one, &mf1, &textconv_one);
101-
fill_one(p->two, &mf2, &textconv_two);
99+
textconv_one = get_textconv(p->one);
100+
textconv_two = get_textconv(p->two);
101+
102+
fill_one(p->one, &mf1, textconv_one);
103+
fill_one(p->two, &mf2, textconv_two);
102104

103105
if (!mf1.ptr) {
104106
if (!mf2.ptr)
@@ -201,14 +203,17 @@ static unsigned int contains(mmfile_t *mf, struct diff_options *o,
201203
static int has_changes(struct diff_filepair *p, struct diff_options *o,
202204
regex_t *regexp, kwset_t kws)
203205
{
204-
struct userdiff_driver *textconv_one = get_textconv(p->one);
205-
struct userdiff_driver *textconv_two = get_textconv(p->two);
206+
struct userdiff_driver *textconv_one = NULL;
207+
struct userdiff_driver *textconv_two = NULL;
206208
mmfile_t mf1, mf2;
207209
int ret;
208210

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

214+
textconv_one = get_textconv(p->one);
215+
textconv_two = get_textconv(p->two);
216+
212217
/*
213218
* If we have an unmodified pair, we know that the count will be the
214219
* same and don't even have to load the blobs. Unless textconv is in
@@ -219,8 +224,8 @@ static int has_changes(struct diff_filepair *p, struct diff_options *o,
219224
if (textconv_one == textconv_two && diff_unmodified_pair(p))
220225
return 0;
221226

222-
fill_one(p->one, &mf1, &textconv_one);
223-
fill_one(p->two, &mf2, &textconv_two);
227+
fill_one(p->one, &mf1, textconv_one);
228+
fill_one(p->two, &mf2, textconv_two);
224229

225230
if (!mf1.ptr) {
226231
if (!mf2.ptr)

0 commit comments

Comments
 (0)