svn commit: r226630 - user/gabor/tre-integration/contrib/tre/lib
Gabor Kovesdan
gabor at FreeBSD.org
Sat Oct 22 11:39:18 UTC 2011
Author: gabor
Date: Sat Oct 22 11:39:17 2011
New Revision: 226630
URL: http://svn.freebsd.org/changeset/base/226630
Log:
- Use the pattern lenght if possible to limit the context that is processed
with the automaton
Modified:
user/gabor/tre-integration/contrib/tre/lib/regexec.c
Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/regexec.c Sat Oct 22 10:29:06 2011 (r226629)
+++ user/gabor/tre-integration/contrib/tre/lib/regexec.c Sat Oct 22 11:39:17 2011 (r226630)
@@ -203,20 +203,29 @@ tre_match(const tre_tnfa_t *tnfa, const
if (ret != REG_OK)
return ret;
- for (so = st + pmatch[0].rm_so - 1; ; so--)
+ if (heur->tlen == -1)
{
- if ((type == STR_WIDE) ? (data_wide[so] == TRE_CHAR('\n')) :
- (data_byte[so] == '\n'))
- break;
- if (so == 0)
- break;
+ for (so = st + pmatch[0].rm_so - 1; ; so--)
+ {
+ if ((type == STR_WIDE) ? (data_wide[so] == TRE_CHAR('\n')) :
+ (data_byte[so] == '\n'))
+ break;
+ if (so == 0)
+ break;
+ }
+
+ for (eo = st + pmatch[0].rm_eo; st + eo < len; eo++)
+ {
+ if ((type == STR_WIDE) ? (data_wide[eo] == TRE_CHAR('\n')) :
+ (data_byte[eo] == '\n'))
+ break;
+ }
}
-
- for (eo = st + pmatch[0].rm_eo; st + eo < len; eo++)
+ else
{
- if ((type == STR_WIDE) ? (data_wide[eo] == TRE_CHAR('\n')) :
- (data_byte[eo] == '\n'))
- break;
+ size_t rem = heur->tlen - (pmatch[0].rm_eo - pmatch[0].rm_so);
+ so = st + pmatch[0].rm_so - rem;
+ eo = st + pmatch[0].rm_eo + rem;
}
SEEK_TO(so);
@@ -272,8 +281,12 @@ tre_match(const tre_tnfa_t *tnfa, const
/* Suffix heuristic not available */
else
{
+ size_t l = (heur->tlen == -1) ? len - st : heur->tlen;
+
+ if (l < len - st)
+ return REG_NOMATCH;
SEEK_TO(st);
- ret = tre_match(tnfa, string, len - st, type, nmatch,
+ ret = tre_match(tnfa, string, l, type, nmatch,
pmatch, eflags, NULL, NULL);
FIX_OFFSETS(st += n);
}
More information about the svn-src-user
mailing list