summaryrefslogtreecommitdiff
path: root/src/stringutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/stringutils.cpp')
-rw-r--r--src/stringutils.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/stringutils.cpp b/src/stringutils.cpp
index e7c8b5b..1ad598d 100644
--- a/src/stringutils.cpp
+++ b/src/stringutils.cpp
@@ -711,9 +711,10 @@ bool isMatch(const std::string &str,
const std::string &exp)
{
static std::unordered_map<std::string, std::regex> re_cache;
- if (re_cache.find(exp) == re_cache.end())
- re_cache.emplace(exp, exp);
- return std::regex_match(str, re_cache[exp]);
+ auto it = re_cache.find(exp);
+ if (it == re_cache.end())
+ it = re_cache.emplace(exp, exp).first;
+ return std::regex_match(str, it->second);
}
bool isMatch(const std::string &str,
@@ -721,9 +722,10 @@ bool isMatch(const std::string &str,
std::smatch &m)
{
static std::unordered_map<std::string, std::regex> re_cache;
- if (re_cache.find(exp) == re_cache.end())
- re_cache.emplace(exp, exp);
- return std::regex_match(str, m, re_cache[exp]);
+ auto it = re_cache.find(exp);
+ if (it == re_cache.end())
+ it = re_cache.emplace(exp, exp).first;
+ return std::regex_match(str, m, it->second);
}
bool fileExists(const std::string &name)