@matheusbsbs / matheus-bagliano / commits / d7eb527d73
Fork 0

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>

René Scharfe committed Mar 7, 2009 at 13:28 UTC d7eb527d731e2a71eaa4597417d879a15588d9ee
2 files changed +18 -17
grep.c
+17 -17
@@ -39,6 +39,8 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
39 {
40 int err;
41
42 + p->word_regexp = opt->word_regexp;
43 +
44 if (opt->fixed || is_fixed(p->pattern))
45 p->fixed = 1;
46 if (opt->regflags & REG_ICASE)
@@ -306,7 +308,8 @@ static struct {
308 { "committer ", 10 },
309 };
310
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)
313 {
314 int hit = 0;
315 int saved_ch = 0;
@@ -338,7 +341,7 @@ static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol
341 hit = !fixmatch(p->pattern, bol, pmatch);
342 }
343
341 - if (hit && opt->word_regexp) {
344 + if (hit && p->word_regexp) {
345 if ((pmatch[0].rm_so < 0) ||
346 (eol - bol) <= pmatch[0].rm_so ||
347 (pmatch[0].rm_eo < 0) ||
@@ -378,35 +381,32 @@ static int match_one_pattern(struct grep_opt *opt, struct grep_pat *p, char *bol
381 return hit;
382 }
383
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)
386 {
387 int h = 0;
388
389 switch (x->node) {
390 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);
392 break;
393 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);
395 break;
396 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))
398 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);
400 break;
401 case GREP_NODE_OR:
402 if (!collect_hits)
403 - return (match_expr_eval(o, x->u.binary.left,
403 + return (match_expr_eval(x->u.binary.left,
404 bol, eol, ctx, 0) ||
405 - match_expr_eval(o, x->u.binary.right,
405 + match_expr_eval(x->u.binary.right,
406 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);
408 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);
410 break;
411 default:
412 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,
420 enum grep_context ctx, int collect_hits)
421 {
422 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);
424 }
425
426 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,
432
433 /* we do not call with collect_hits without being extended */
434 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))
436 return 1;
437 }
438 return 0;
grep.h
+1
@@ -31,6 +31,7 @@ struct grep_pat {
31 enum grep_header_field field;
32 regex_t regexp;
33 unsigned fixed:1;
34 + unsigned word_regexp:1;
35 };
36
37 enum grep_expr_node {