Author: amassari
Date: Tue Aug 28 05:16:49 2007
New Revision: 570396
URL: http://svn.apache.org/viewvc?rev=570396&view=rev
Log:
When matching a union, stop testing the various alternatives if one reaches the
end of the input string
Modified:
xerces/c/branches/xerces-2.7/src/xercesc/util/regx/RegularExpression.cpp
Modified:
xerces/c/branches/xerces-2.7/src/xercesc/util/regx/RegularExpression.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/branches/xerces-2.7/src/xercesc/util/regx/RegularExpression.cpp?rev=570396&r1=570395&r2=570396&view=diff
==============================================================================
--- xerces/c/branches/xerces-2.7/src/xercesc/util/regx/RegularExpression.cpp
(original)
+++ xerces/c/branches/xerces-2.7/src/xercesc/util/regx/RegularExpression.cpp
Tue Aug 28 05:16:49 2007
@@ -1391,22 +1391,25 @@
const Op* const op, int 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 && ret <= context->fLimit && ret>bestResult)
- {
- bestResult=ret;
- bestResultContext=tmpContext;
- }
- }
- if(bestResult!=-1)
- *context=bestResultContext;
- return bestResult;
+ 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 && 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;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]