From owner-svn-src-user@FreeBSD.ORG Thu Aug 18 17:53:19 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 86043106564A; Thu, 18 Aug 2011 17:53:19 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6C5368FC13; Thu, 18 Aug 2011 17:53:19 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p7IHrJri067635; Thu, 18 Aug 2011 17:53:19 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7IHrJxE067632; Thu, 18 Aug 2011 17:53:19 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201108181753.p7IHrJxE067632@svn.freebsd.org> From: Gabor Kovesdan Date: Thu, 18 Aug 2011 17:53:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r224982 - user/gabor/grep/trunk X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2011 17:53:19 -0000 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;