Skip to content

Commit e0b9f8a

Browse files
avargitster
authored andcommitted
grep: remove redundant regflags assignments
Remove redundant assignments to the "regflags" variable. This variable is only used set under GREP_PATTERN_TYPE_ERE, so there's no need to un-set it under GREP_PATTERN_TYPE_{FIXED,BRE,PCRE}. Back in 5010cb5[1], we did do "opt.regflags &= ~REG_EXTENDED" upon seeing "-G" on the command line and flipped the bit on upon seeing "-E", but I think that was perfectly sensible and it would have been a bug if we didn't. They were part of the command line parsing that could have seen "-E" on the command line earlier. When cca2c17 ("git-grep: do not die upon -F/-P when grep.extendedRegexp is set.", 2011-05-09) switched the command line parsing to "read into a 'tentatively this is what we saw the last' variable and then finally commit just once", we didn't touch opt.regflags for PCRE and FIXED, but we still had to flip regflags between BRE and ERE, because parsing of grep.extendedregexp configuration variable directly touched opt.regflags back then, which was done by b22520a ("grep: allow -E and -n to be turned on by default via configuration", 2011-03-30). When 84befcd ("grep: add a grep.patternType configuration setting", 2012-08-03) introduced extended_regexp_option field, we stopped flipping regflags while reading the configuration, and that was when we should have noticed and stopped dropping REG_EXTENDED bit in the "now we can commit what type to use" helper function. There is no reason to do this anymore, so stop doing it, more to reduce "wait this is used under fixed/BRE/PCRE how?" confusion when reading the code, than to to save ourselves trivial CPU cycles by removing one assignment. 1. "built-in "git grep"", 2006-04-30. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 374166c commit e0b9f8a

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

grep.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st
179179
case GREP_PATTERN_TYPE_BRE:
180180
opt->fixed = 0;
181181
opt->pcre = 0;
182-
opt->regflags &= ~REG_EXTENDED;
183182
break;
184183

185184
case GREP_PATTERN_TYPE_ERE:
@@ -191,13 +190,11 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st
191190
case GREP_PATTERN_TYPE_FIXED:
192191
opt->fixed = 1;
193192
opt->pcre = 0;
194-
opt->regflags &= ~REG_EXTENDED;
195193
break;
196194

197195
case GREP_PATTERN_TYPE_PCRE:
198196
opt->fixed = 0;
199197
opt->pcre = 1;
200-
opt->regflags &= ~REG_EXTENDED;
201198
break;
202199
}
203200
}
@@ -415,10 +412,9 @@ static void compile_fixed_regexp(struct grep_pat *p, struct grep_opt *opt)
415412
{
416413
struct strbuf sb = STRBUF_INIT;
417414
int err;
418-
int regflags;
415+
int regflags = opt->regflags;
419416

420417
basic_regex_quote_buf(&sb, p->pattern);
421-
regflags = opt->regflags & ~REG_EXTENDED;
422418
if (opt->ignore_case)
423419
regflags |= REG_ICASE;
424420
err = regcomp(&p->regexp, sb.buf, regflags);

0 commit comments

Comments
 (0)