Skip to content

Commit d7eb527

Browse files
René Scharfegitster
authored andcommitted
grep: remove grep_opt argument from match_expr_eval()
The only use of the struct grep_opt argument of match_expr_eval() is to pass the option word_regexp to match_one_pattern(). By adding a pattern flag for it we can reduce the number of function arguments of these two functions, as a cleanup and preparation for adding more in the next patch. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 252d560 commit d7eb527

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

grep.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
3939
{
4040
int err;
4141

42+
p->word_regexp = opt->word_regexp;
43+
4244
if (opt->fixed || is_fixed(p->pattern))
4345
p->fixed = 1;
4446
if (opt->regflags & REG_ICASE)
@@ -306,7 +308,8 @@ static struct {
306308
{ "committer ", 10 },
307309
};
308310

309-
static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol, char *eol, enum grep_context ctx)
311+
static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
312+
enum grep_context ctx)
310313
{
311314
int hit = 0;
312315
int saved_ch = 0;
@@ -338,7 +341,7 @@ static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol
338341
hit = !fixmatch(p->pattern, bol, pmatch);
339342
}
340343

341-
if (hit && opt->word_regexp) {
344+
if (hit && p->word_regexp) {
342345
if ((pmatch[0].rm_so < 0) ||
343346
(eol - bol) <= pmatch[0].rm_so ||
344347
(pmatch[0].rm_eo < 0) ||
@@ -378,35 +381,32 @@ static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol
378381
return hit;
379382
}
380383

381-
static int match_expr_eval(struct grep_opt *o,
382-
struct grep_expr *x,
383-
char *bol, char *eol,
384-
enum grep_context ctx,
385-
int collect_hits)
384+
static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
385+
enum grep_context ctx, int collect_hits)
386386
{
387387
int h = 0;
388388

389389
switch (x->node) {
390390
case GREP_NODE_ATOM:
391-
h = match_one_pattern(o, x->u.atom, bol, eol, ctx);
391+
h = match_one_pattern(x->u.atom, bol, eol, ctx);
392392
break;
393393
case GREP_NODE_NOT:
394-
h = !match_expr_eval(o, x->u.unary, bol, eol, ctx, 0);
394+
h = !match_expr_eval(x->u.unary, bol, eol, ctx, 0);
395395
break;
396396
case GREP_NODE_AND:
397-
if (!match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0))
397+
if (!match_expr_eval(x->u.binary.left, bol, eol, ctx, 0))
398398
return 0;
399-
h = match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 0);
399+
h = match_expr_eval(x->u.binary.right, bol, eol, ctx, 0);
400400
break;
401401
case GREP_NODE_OR:
402402
if (!collect_hits)
403-
return (match_expr_eval(o, x->u.binary.left,
403+
return (match_expr_eval(x->u.binary.left,
404404
bol, eol, ctx, 0) ||
405-
match_expr_eval(o, x->u.binary.right,
405+
match_expr_eval(x->u.binary.right,
406406
bol, eol, ctx, 0));
407-
h = match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0);
407+
h = match_expr_eval(x->u.binary.left, bol, eol, ctx, 0);
408408
x->u.binary.left->hit |= h;
409-
h |= match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 1);
409+
h |= match_expr_eval(x->u.binary.right, bol, eol, ctx, 1);
410410
break;
411411
default:
412412
die("Unexpected node type (internal error) %d", x->node);
@@ -420,7 +420,7 @@ static int match_expr(struct grep_opt *opt, char *bol, char *eol,
420420
enum grep_context ctx, int collect_hits)
421421
{
422422
struct grep_expr *x = opt->pattern_expression;
423-
return match_expr_eval(opt, x, bol, eol, ctx, collect_hits);
423+
return match_expr_eval(x, bol, eol, ctx, collect_hits);
424424
}
425425

426426
static int match_line(struct grep_opt *opt, char *bol, char *eol,
@@ -432,7 +432,7 @@ static int match_line(struct grep_opt *opt, char *bol, char *eol,
432432

433433
/* we do not call with collect_hits without being extended */
434434
for (p = opt->pattern_list; p; p = p->next) {
435-
if (match_one_pattern(opt, p, bol, eol, ctx))
435+
if (match_one_pattern(p, bol, eol, ctx))
436436
return 1;
437437
}
438438
return 0;

grep.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct grep_pat {
3131
enum grep_header_field field;
3232
regex_t regexp;
3333
unsigned fixed:1;
34+
unsigned word_regexp:1;
3435
};
3536

3637
enum grep_expr_node {

0 commit comments

Comments
 (0)