From: Thiago Farina <tfransosi@gmail.com>
To: Bert Wesarg <bert.wesarg@googlemail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH/RFC 1/4] grep: prepare for re-using the space of the regexp member in struct grep_pat
Date: Mon, 2 May 2011 10:27:28 -0300 [thread overview]
Message-ID: <BANLkTi=5Rr2t-u9dJCg6EpcbfEALJDY4wQ@mail.gmail.com> (raw)
In-Reply-To: <f768ea6e107cdd229a18df0bac3bf583eb1f9fc5.1304321122.git.bert.wesarg@googlemail.com>
On Mon, May 2, 2011 at 8:39 AM, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> ---
> grep.c | 12 ++++++------
> grep.h | 4 +++-
> 2 files changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/grep.c b/grep.c
> index 63c4280..b8eda9e 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -70,7 +70,7 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
> if (p->fixed)
> return;
>
> - err = regcomp(&p->regexp, p->pattern, opt->regflags);
> + err = regcomp(&p->u.regexp, p->pattern, opt->regflags);
> if (err) {
> char errbuf[1024];
> char where[1024];
> @@ -81,8 +81,8 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
> sprintf(where, "%s, ", p->origin);
> else
> where[0] = 0;
> - regerror(err, &p->regexp, errbuf, 1024);
> - regfree(&p->regexp);
> + regerror(err, &p->u.regexp, errbuf, 1024);
> + regfree(&p->u.regexp);
> die("%s'%s': %s", where, p->pattern, errbuf);
> }
> }
> @@ -320,7 +320,7 @@ void free_grep_patterns(struct grep_opt *opt)
> case GREP_PATTERN: /* atom */
> case GREP_PATTERN_HEAD:
> case GREP_PATTERN_BODY:
> - regfree(&p->regexp);
> + regfree(&p->u.regexp);
> break;
> default:
> break;
> @@ -464,7 +464,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
> if (p->fixed)
> hit = !fixmatch(p, bol, eol, pmatch);
> else
> - hit = !regmatch(&p->regexp, bol, eol, pmatch, eflags);
> + hit = !regmatch(&p->u.regexp, bol, eol, pmatch, eflags);
>
> if (hit && p->word_regexp) {
> if ((pmatch[0].rm_so < 0) ||
> @@ -794,7 +794,7 @@ static int look_ahead(struct grep_opt *opt,
> if (p->fixed)
> hit = !fixmatch(p, bol, bol + *left_p, &m);
> else
> - hit = !regmatch(&p->regexp, bol, bol + *left_p, &m, 0);
> + hit = !regmatch(&p->u.regexp, bol, bol + *left_p, &m, 0);
> if (!hit || m.rm_so < 0 || m.rm_eo < 0)
> continue;
> if (earliest < 0 || m.rm_so < earliest)
> diff --git a/grep.h b/grep.h
> index 06621fe..9912c11 100644
> --- a/grep.h
> +++ b/grep.h
> @@ -32,7 +32,9 @@ struct grep_pat {
> const char *pattern;
> size_t patternlen;
> enum grep_header_field field;
> - regex_t regexp;
> + union {
> + regex_t regexp;
> + } u;
Instead of u, would be worth to rename it to something more descriptive?
> unsigned fixed:1;
> unsigned ignore_case:1;
> unsigned word_regexp:1;
> --
> 1.7.5.349.gfeb1a
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
next prev parent reply other threads:[~2011-05-02 13:27 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-02 11:39 [PATCH/RFC 0/4] grep: support to match by line number Bert Wesarg
[not found] ` <cover.1304321122.git.bert.wesarg@googlemail.com>
2011-05-02 11:39 ` [PATCH/RFC 1/4] grep: prepare for re-using the space of the regexp member in struct grep_pat Bert Wesarg
2011-05-02 13:27 ` Thiago Farina [this message]
2011-05-02 14:25 ` Bert Wesarg
2011-05-02 11:39 ` [PATCH/RFC 2/4] grep: pass current line number down to match_one_pattern Bert Wesarg
2011-05-02 13:30 ` Thiago Farina
2011-05-02 14:29 ` Bert Wesarg
2011-05-02 16:40 ` Junio C Hamano
2011-05-02 11:39 ` [PATCH/RFC 3/4] grep: introduce pattern which matches at line number Bert Wesarg
2011-05-02 13:33 ` Thiago Farina
2011-05-02 14:32 ` Bert Wesarg
2011-05-02 11:39 ` [PATCH/RFC 4/4] grep: provide option to match " Bert Wesarg
2011-05-02 11:54 ` [PATCH/RFC 0/4] grep: support to match by " Sverre Rabbelier
2011-05-02 12:20 ` Bert Wesarg
2011-05-02 16:46 ` Junio C Hamano
2011-05-02 19:14 ` Bert Wesarg
2011-05-02 19:30 ` Junio C Hamano
2011-05-02 16:38 ` Junio C Hamano
2011-05-02 17:11 ` Jakub Narebski
2011-05-02 18:54 ` Bert Wesarg
2011-05-02 19:08 ` Junio C Hamano
2011-05-02 19:33 ` Bert Wesarg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='BANLkTi=5Rr2t-u9dJCg6EpcbfEALJDY4wQ@mail.gmail.com' \
--to=tfransosi@gmail.com \
--cc=bert.wesarg@googlemail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).