From owner-svn-src-user@FreeBSD.ORG Thu Sep 1 13:51:27 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 5ADDE106564A; Thu, 1 Sep 2011 13:51:27 +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 4B3F18FC0A; Thu, 1 Sep 2011 13:51:27 +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 p81DpR6w053983; Thu, 1 Sep 2011 13:51:27 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p81DpRv1053980; Thu, 1 Sep 2011 13:51:27 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201109011351.p81DpRv1053980@svn.freebsd.org> From: Gabor Kovesdan Date: Thu, 1 Sep 2011 13:51:27 +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: r225311 - user/gabor/grep/trunk/regex 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, 01 Sep 2011 13:51:27 -0000 Author: gabor Date: Thu Sep 1 13:51:26 2011 New Revision: 225311 URL: http://svn.freebsd.org/changeset/base/225311 Log: - Merge improvements from TRE: * Support for 0-length pattern (matches everything) * Do not modify pmatch when pattern is compiled with REG_NOSUB Modified: user/gabor/grep/trunk/regex/fastmatch.h user/gabor/grep/trunk/regex/tre-fastmatch.c Modified: user/gabor/grep/trunk/regex/fastmatch.h ============================================================================== --- user/gabor/grep/trunk/regex/fastmatch.h Thu Sep 1 13:40:41 2011 (r225310) +++ user/gabor/grep/trunk/regex/fastmatch.h Thu Sep 1 13:51:26 2011 (r225311) @@ -3,7 +3,6 @@ #ifndef FASTMATCH_H #define FASTMATCH_H 1 -#include #include #include #include @@ -18,8 +17,9 @@ typedef struct { int *bmGs; char *pattern; int defBc; - hashtable *qsBc_table; + void *qsBc_table; int *sbmGs; + const char *re_endp; /* flags */ bool bol; @@ -27,6 +27,8 @@ typedef struct { bool word; bool icase; bool newline; + bool nosub; + bool matchall; } fastmatch_t; extern int Modified: user/gabor/grep/trunk/regex/tre-fastmatch.c ============================================================================== --- user/gabor/grep/trunk/regex/tre-fastmatch.c Thu Sep 1 13:40:41 2011 (r225310) +++ user/gabor/grep/trunk/regex/tre-fastmatch.c Thu Sep 1 13:51:26 2011 (r225311) @@ -232,8 +232,8 @@ static int fastcmp(const void *, const v fg->defBc = fg->wlen - fg->hasdot; \ \ /* Preprocess pattern. */ \ - fg->qsBc_table = hashtable_init(fg->wlen * 8, sizeof(tre_char_t), \ - sizeof(int)); \ + fg->qsBc_table = hashtable_init(fg->wlen * (fg->icase ? 8 : 4), \ + sizeof(tre_char_t), sizeof(int)); \ if (!fg->qsBc_table) \ FAIL_COMP(REG_ESPACE); \ for (unsigned int i = fg->hasdot + 1; i < fg->wlen; i++) \ @@ -385,13 +385,17 @@ static int fastcmp(const void *, const v fg->icase = (cflags & REG_ICASE); \ fg->word = (cflags & REG_WORD); \ fg->newline = (cflags & REG_NEWLINE); \ + fg->nosub = (cflags & REG_NOSUB); \ + \ + if (n == 0) \ + { \ + fg->matchall = true; \ + return REG_OK; \ + } \ \ /* Cannot handle REG_ICASE with MB string */ \ if (fg->icase && (TRE_MB_CUR_MAX > 1)) \ return REG_BADPAT; \ - \ - /* Calculate length if unspecified */ \ - n = (n == 0) ? tre_strlen(pat) : n; /* * Returns: REG_OK on success, error code otherwise @@ -598,6 +602,16 @@ tre_match_fast(const fastmatch_t *fg, co break; } + if (fg->matchall) + { + if (!fg->nosub) + { + pmatch[0].rm_so = 0; + pmatch[0].rm_eo = len; + } + return REG_OK; + } + /* No point in going farther if we do not have enough data. */ switch (type) { @@ -642,8 +656,11 @@ tre_match_fast(const fastmatch_t *fg, co { if (fg->word && !IS_ON_WORD_BOUNDARY) return ret; - pmatch[0].rm_so = j; - pmatch[0].rm_eo = j + (type == STR_WIDE ? fg->wlen : fg->len); + if (!fg->nosub) + { + pmatch[0].rm_so = j; + pmatch[0].rm_eo = j + (type == STR_WIDE ? fg->wlen : fg->len); + } return REG_OK; } } @@ -663,8 +680,11 @@ tre_match_fast(const fastmatch_t *fg, co CHECK_BOL_ANCHOR; if (fg->eol) CHECK_EOL_ANCHOR; - pmatch[0].rm_so = j; - pmatch[0].rm_eo = j + ((type == STR_WIDE) ? fg->wlen : fg->len); + if (!fg->nosub) + { + pmatch[0].rm_so = j; + pmatch[0].rm_eo = j + ((type == STR_WIDE) ? fg->wlen : fg->len); + } return REG_OK; } else if (mismatch > 0)