You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2007/08/28 14:26:31 UTC
svn commit: r570398 -
/xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp
Author: amassari
Date: Tue Aug 28 05:26:31 2007
New Revision: 570398
URL: http://svn.apache.org/viewvc?rev=570398&view=rev
Log:
When matching a union, stop testing the various alternatives if one reaches the end of the input string
Modified:
xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp
Modified: xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp?rev=570398&r1=570397&r2=570398&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp Tue Aug 28 05:26:31 2007
@@ -593,6 +593,10 @@
}
}
+ // if the length is less than the minimum length, we cannot possibly match
+ if(context.fLimit<fMinLength)
+ return false;
+
XMLSize_t limit = context.fLimit - fMinLength;
XMLSize_t matchStart;
int matchEnd = -1;
@@ -1158,6 +1162,7 @@
if (tmpOp->getOpType() == Op::O_CLOSURE) {
XMLInt32 id = tmpOp->getData();
if (id >= 0) {
+ // loop has ended, reset the status for this closure
context->fOffsets[id] = -1;
}
}
@@ -1448,22 +1453,25 @@
const Op* const op, XMLSize_t offset,
const short direction)
{
- unsigned int opSize = op->getSize();
+ unsigned int opSize = op->getSize();
- Context bestResultContext;
- int bestResult=-1;
- for(unsigned int i=0; i < opSize; i++) {
- Context tmpContext(context);
- int ret = match(&tmpContext, op->elementAt(i), offset, direction);
- if (ret >= 0 && (XMLSize_t)ret <= context->fLimit && ret>bestResult)
- {
- bestResult=ret;
- bestResultContext=tmpContext;
- }
- }
- if(bestResult!=-1)
+ Context bestResultContext;
+ int bestResult=-1;
+ for(unsigned int i=0; i < opSize; i++) {
+ Context tmpContext(context);
+ int ret = match(&tmpContext, op->elementAt(i), offset, direction);
+ if (ret >= 0 && (XMLSize_t)ret <= context->fLimit && ret>bestResult)
+ {
+ bestResult=ret;
+ bestResultContext=tmpContext;
+ // exit early, if we reached the end of the string
+ if(ret == context->fLimit)
+ break;
+ }
+ }
+ if(bestResult!=-1)
*context=bestResultContext;
- return bestResult;
+ return bestResult;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org