From 36136f1003058d48feaadd6a3331a0a18ea708f9 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Thu, 10 Aug 2017 13:19:26 +1000 Subject: [PATCH] fdr_compile: don't do string copies in isSuffix --- src/fdr/fdr_compile.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/fdr/fdr_compile.cpp b/src/fdr/fdr_compile.cpp index 770f30fe..e50245d7 100644 --- a/src/fdr/fdr_compile.cpp +++ b/src/fdr/fdr_compile.cpp @@ -638,16 +638,17 @@ bytecode_ptr FDRCompiler::build() { static bool isSuffix(const hwlmLiteral &lit1, const hwlmLiteral &lit2) { - auto s1 = lit1.s; - auto s2 = lit2.s; - if (lit1.nocase || lit2.nocase) { - upperString(s1); - upperString(s2); - } + const auto &s1 = lit1.s; + const auto &s2 = lit2.s; size_t len1 = s1.length(); size_t len2 = s2.length(); assert(len1 >= len2); - return equal(s2.begin(), s2.end(), s1.begin() + len1 - len2); + + auto lit_cmp = (lit1.nocase || lit2.nocase) + ? [](char a, char b) { return mytoupper(a) == mytoupper(b); } + : [](char a, char b) { return a == b; }; + + return equal(s2.begin(), s2.end(), s1.begin() + len1 - len2, lit_cmp); } /*