Re: [PATCH/RFC 1/4] grep: prepare for re-using the space of the regexp member in struct grep_pat

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 2, 2011 at 8:39 AM, Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx> wrote:
> Signed-off-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx>
> ---
> Â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@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>
ÿô.nlj·Ÿ®‰­†+%ŠË±é¥Šwÿº{.nlj· ŠßžØn‡r¡öë¨è&£ûz¹Þúzf£¢·hšˆ§~†­†Ûÿÿïÿ‘ê_èæ+v‰¨þ)ßø

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]