Removed support for patterns like |a|b and a||b (equal to a|b|)
-> Improved performance by 1,3% (non-matchcompiled build)
This commit is contained in:
parent
d19b5031fa
commit
4b9241f643
|
@ -324,7 +324,7 @@ const std::string &Token::strAt(int index) const
|
||||||
return tok ? tok->_str : emptyString;
|
return tok ? tok->_str : emptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int multiComparePercent(const Token *tok, const char*& haystack, bool emptyStringFound, unsigned int varid)
|
static int multiComparePercent(const Token *tok, const char*& haystack, unsigned int varid)
|
||||||
{
|
{
|
||||||
++haystack;
|
++haystack;
|
||||||
// Compare only the first character of the string for optimization reasons
|
// Compare only the first character of the string for optimization reasons
|
||||||
|
@ -458,8 +458,6 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
|
||||||
|
|
||||||
if (*haystack == '|')
|
if (*haystack == '|')
|
||||||
haystack += 1;
|
haystack += 1;
|
||||||
else if (*haystack == ' ' || *haystack == '\0')
|
|
||||||
return emptyStringFound ? 0 : -1;
|
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -468,22 +466,17 @@ static int multiComparePercent(const Token *tok, const char*& haystack, bool emp
|
||||||
|
|
||||||
int Token::multiCompare(const Token *tok, const char *haystack, unsigned int varid)
|
int Token::multiCompare(const Token *tok, const char *haystack, unsigned int varid)
|
||||||
{
|
{
|
||||||
bool emptyStringFound = false;
|
|
||||||
const char *needle = tok->str().c_str();
|
const char *needle = tok->str().c_str();
|
||||||
const char *needlePointer = needle;
|
const char *needlePointer = needle;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (needlePointer == needle && haystack[0] == '%' && haystack[1] != '|' && haystack[1] != '\0' && haystack[1] != ' ') {
|
if (needlePointer == needle && haystack[0] == '%' && haystack[1] != '|' && haystack[1] != '\0' && haystack[1] != ' ') {
|
||||||
int ret = multiComparePercent(tok, haystack, emptyStringFound, varid);
|
int ret = multiComparePercent(tok, haystack, varid);
|
||||||
if (ret < 2)
|
if (ret < 2)
|
||||||
return ret;
|
return ret;
|
||||||
} else if (*haystack == '|') {
|
} else if (*haystack == '|') {
|
||||||
if (*needlePointer == 0) {
|
if (*needlePointer == 0) {
|
||||||
// If needle is at the end, we have a match.
|
// If needle is at the end, we have a match.
|
||||||
return 1;
|
return 1;
|
||||||
} else if (needlePointer == needle) {
|
|
||||||
// If needlePointer was not increased at all, we had a empty
|
|
||||||
// string in the haystack
|
|
||||||
emptyStringFound = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
needlePointer = needle;
|
needlePointer = needle;
|
||||||
|
@ -508,7 +501,7 @@ int Token::multiCompare(const Token *tok, const char *haystack, unsigned int var
|
||||||
} while (*haystack != ' ' && *haystack != '|' && *haystack);
|
} while (*haystack != ' ' && *haystack != '|' && *haystack);
|
||||||
|
|
||||||
if (*haystack == ' ' || *haystack == '\0') {
|
if (*haystack == ' ' || *haystack == '\0') {
|
||||||
return emptyStringFound ? 0 : -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
++haystack;
|
++haystack;
|
||||||
|
@ -518,10 +511,6 @@ int Token::multiCompare(const Token *tok, const char *haystack, unsigned int var
|
||||||
if (*needlePointer == '\0')
|
if (*needlePointer == '\0')
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// If empty string was found earlier from the haystack
|
|
||||||
if (emptyStringFound)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,8 +138,6 @@ private:
|
||||||
// Test for empty string found
|
// Test for empty string found
|
||||||
Token notfound(0);
|
Token notfound(0);
|
||||||
notfound.str("notfound");
|
notfound.str("notfound");
|
||||||
ASSERT_EQUALS(0, Token::multiCompare(¬found, "|one|two", 0));
|
|
||||||
ASSERT_EQUALS(0, Token::multiCompare(¬found, "one||two", 0));
|
|
||||||
ASSERT_EQUALS(0, Token::multiCompare(¬found, "one|two|", 0));
|
ASSERT_EQUALS(0, Token::multiCompare(¬found, "one|two|", 0));
|
||||||
|
|
||||||
// Test for not found
|
// Test for not found
|
||||||
|
|
|
@ -158,8 +158,8 @@ class MatchCompiler:
|
||||||
ret += ' if (!tok || tok->str().size()!=1U || !strchr("' + tok[1:-1] + '", tok->str()[0]))\n'
|
ret += ' if (!tok || tok->str().size()!=1U || !strchr("' + tok[1:-1] + '", tok->str()[0]))\n'
|
||||||
ret += ' ' + returnStatement
|
ret += ' ' + returnStatement
|
||||||
|
|
||||||
# a|b|c
|
# a|b|c
|
||||||
elif tok.find('|') >= 0 and tok != '||' and tok != '|' and tok != '|=':
|
elif tok.find('|') > 0:
|
||||||
tokens2 = tok.split('|')
|
tokens2 = tok.split('|')
|
||||||
logicalOp = None
|
logicalOp = None
|
||||||
neg = None
|
neg = None
|
||||||
|
|
Loading…
Reference in New Issue