diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/stringutils.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/stringutils.cpp b/src/stringutils.cpp index 74cb0e7..e6f3b80 100644 --- a/src/stringutils.cpp +++ b/src/stringutils.cpp @@ -711,7 +711,8 @@ bool isMatch(const std::string &str, const std::string &exp) { static std::unordered_map<std::string, jp::Regex> re_cache; - if (re_cache.find(exp) == re_cache.end()) + auto it = re_cache.find(exp); + if (it == re_cache.end()) { jp::Regex re(exp, "x"); if (!re) @@ -720,9 +721,9 @@ bool isMatch(const std::string &str, re.getErrorMessage().c_str(), re.getErrorOffset()); exit(1); } - re_cache[exp] = re; + it = re_cache.insert({ exp, re }).first; } - return re_cache[exp].match(str); + return it->second.match(str); } bool isMatch(const std::string &str, @@ -730,7 +731,8 @@ bool isMatch(const std::string &str, jp::VecNum &m) { static std::unordered_map<std::string, jp::Regex> re_cache; - if (re_cache.find(exp) == re_cache.end()) + auto it = re_cache.find(exp); + if (it == re_cache.end()) { jp::Regex re(exp, "x"); if (!re) @@ -739,10 +741,10 @@ bool isMatch(const std::string &str, re.getErrorMessage().c_str(), re.getErrorOffset()); exit(1); } - re_cache[exp] = re; + it = re_cache.insert({ exp, re }).first; } jp::RegexMatch rm; - size_t count = rm.setRegexObject(&re_cache[exp]) + size_t count = rm.setRegexObject(&it->second) .setSubject(&str) .setNumberedSubstringVector(&m) .match(); |