summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-03-05 12:08:52 +0300
committerewewukek <ewewukek@gmail.com>2024-03-05 12:08:52 +0300
commit2851cf706220be4629c4d9ff6a35ea1f05acae18 (patch)
tree12039d363365fdc79201e9a608ce2e5cfb67223a
parent31f7c8009e2d6bf09328f2597633ee8e2cfa68de (diff)
downloadmplint-2851cf706220be4629c4d9ff6a35ea1f05acae18.tar.gz
mplint-2851cf706220be4629c4d9ff6a35ea1f05acae18.tar.bz2
mplint-2851cf706220be4629c4d9ff6a35ea1f05acae18.tar.xz
mplint-2851cf706220be4629c4d9ff6a35ea1f05acae18.zip
Use iterator returned by find() to avoid second searchHEADmaster
-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)