svn commit: r225311 - user/gabor/grep/trunk/regex
Gabor Kovesdan
gabor at FreeBSD.org
Thu Sep 1 13:51:27 UTC 2011
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 <hashtable.h>
#include <limits.h>
#include <regex.h>
#include <stdbool.h>
@@ -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)
More information about the svn-src-user
mailing list