diff options
author | ewewukek <ewewukek@gmail.com> | 2024-03-05 12:08:52 +0300 |
---|---|---|
committer | ewewukek <ewewukek@gmail.com> | 2024-03-05 12:08:52 +0300 |
commit | 2851cf706220be4629c4d9ff6a35ea1f05acae18 (patch) | |
tree | 12039d363365fdc79201e9a608ce2e5cfb67223a | |
parent | 31f7c8009e2d6bf09328f2597633ee8e2cfa68de (diff) | |
download | mplint-master.tar.gz mplint-master.tar.bz2 mplint-master.tar.xz mplint-master.zip |
-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 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) |