From 4b9241f643841697aeb225e3412c40aa109e268a Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 1 Feb 2016 09:55:16 +0100 Subject: [PATCH] Removed support for patterns like |a|b and a||b (equal to a|b|) -> Improved performance by 1,3% (non-matchcompiled build) --- lib/token.cpp | 17 +++-------------- test/testtoken.cpp | 2 -- tools/matchcompiler.py | 4 ++-- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/lib/token.cpp b/lib/token.cpp index 908f11273..de71c096b 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -324,7 +324,7 @@ const std::string &Token::strAt(int index) const 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; // 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 == '|') haystack += 1; - else if (*haystack == ' ' || *haystack == '\0') - return emptyStringFound ? 0 : -1; else 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) { - bool emptyStringFound = false; const char *needle = tok->str().c_str(); const char *needlePointer = needle; for (;;) { 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) return ret; } else if (*haystack == '|') { if (*needlePointer == 0) { // If needle is at the end, we have a match. 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; @@ -508,7 +501,7 @@ int Token::multiCompare(const Token *tok, const char *haystack, unsigned int var } while (*haystack != ' ' && *haystack != '|' && *haystack); if (*haystack == ' ' || *haystack == '\0') { - return emptyStringFound ? 0 : -1; + return -1; } ++haystack; @@ -518,10 +511,6 @@ int Token::multiCompare(const Token *tok, const char *haystack, unsigned int var if (*needlePointer == '\0') return 1; - // If empty string was found earlier from the haystack - if (emptyStringFound) - return 0; - return -1; } diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 25c7aa261..c9f6da8e2 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -138,8 +138,6 @@ private: // Test for empty string found Token notfound(0); 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)); // Test for not found diff --git a/tools/matchcompiler.py b/tools/matchcompiler.py index 9b2dc346c..2104d8903 100755 --- a/tools/matchcompiler.py +++ b/tools/matchcompiler.py @@ -158,8 +158,8 @@ class MatchCompiler: ret += ' if (!tok || tok->str().size()!=1U || !strchr("' + tok[1:-1] + '", tok->str()[0]))\n' ret += ' ' + returnStatement - # a|b|c - elif tok.find('|') >= 0 and tok != '||' and tok != '|' and tok != '|=': + # a|b|c + elif tok.find('|') > 0: tokens2 = tok.split('|') logicalOp = None neg = None