Date: Thu, 18 Aug 2011 17:53:19 +0000 (UTC) From: Gabor Kovesdan <gabor@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r224982 - user/gabor/grep/trunk Message-ID: <201108181753.p7IHrJxE067632@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gabor Date: Thu Aug 18 17:53:19 2011 New Revision: 224982 URL: http://svn.freebsd.org/changeset/base/224982 Log: - Pass the pattern length to the matcher instead of calculating it twice Modified: user/gabor/grep/trunk/grep.c user/gabor/grep/trunk/grep.h Modified: user/gabor/grep/trunk/grep.c ============================================================================== --- user/gabor/grep/trunk/grep.c Thu Aug 18 17:12:01 2011 (r224981) +++ user/gabor/grep/trunk/grep.c Thu Aug 18 17:53:19 2011 (r224982) @@ -82,7 +82,7 @@ bool matchall; /* Searching patterns */ unsigned int patterns, pattern_sz; -char **pattern; +struct pat *pattern; regex_t *r_pattern; fastmatch_t *fg_pattern; @@ -233,14 +233,15 @@ add_pattern(char *pat, size_t len) if (patterns == pattern_sz) { pattern_sz *= 2; pattern = grep_realloc(pattern, ++pattern_sz * - sizeof(*pattern)); + sizeof(struct pat)); } if (len > 0 && pat[len - 1] == '\n') --len; /* pat may not be NUL-terminated */ - pattern[patterns] = grep_malloc(len + 1); - memcpy(pattern[patterns], pat, len); - pattern[patterns][len] = '\0'; + pattern[patterns].pat = grep_malloc(len + 1); + memcpy(pattern[patterns].pat, pat, len); + pattern[patterns].len = len; + pattern[patterns].pat[len] = '\0'; ++patterns; } @@ -652,19 +653,18 @@ main(int argc, char *argv[]) fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern)); r_pattern = grep_calloc(patterns, sizeof(*r_pattern)); -/* - * XXX: fgrepcomp() and fastcomp() are workarounds for regexec() performance. - * Optimizations should be done there. - */ - /* Check if cheating is allowed (always is for fgrep). */ + + /* Check if cheating is allowed (always is for fgrep). */ if (grepbehave == GREP_FIXED) { for (i = 0; i < patterns; ++i) - fixcomp(&fg_pattern[i], pattern[i], cflags); + fixncomp(&fg_pattern[i], pattern[i].pat, + pattern[i].len, cflags); } else { for (i = 0; i < patterns; ++i) { - if (fastcomp(&fg_pattern[i], pattern[i], cflags) != 0) { + if (fastncomp(&fg_pattern[i], pattern[i].pat, + pattern[i].len, cflags) != 0) { /* Fall back to full regex library */ - c = regcomp(&r_pattern[i], pattern[i], cflags); + c = regcomp(&r_pattern[i], pattern[i].pat, cflags); if (c != 0) { regerror(c, &r_pattern[i], re_error, RE_ERROR_BUF); Modified: user/gabor/grep/trunk/grep.h ============================================================================== --- user/gabor/grep/trunk/grep.h Thu Aug 18 17:12:01 2011 (r224981) +++ user/gabor/grep/trunk/grep.h Thu Aug 18 17:53:19 2011 (r224982) @@ -92,6 +92,11 @@ struct str { int line_no; }; +struct pat { + char *pat; + int len; +}; + struct epat { char *pat; int mode; @@ -113,7 +118,7 @@ extern int binbehave, devbehave, dirbeh extern bool first, matchall, notfound, prev; extern int tail; extern unsigned int dpatterns, fpatterns, patterns; -extern char **pattern; +extern struct pat *pattern; extern struct epat *dpattern, *fpattern; extern regex_t *er_pattern, *r_pattern; extern fastmatch_t *fg_pattern;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108181753.p7IHrJxE067632>