summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-02-25 04:04:28 +0300
committerewewukek <ewewukek@gmail.com>2024-02-25 04:04:28 +0300
commit31f7c8009e2d6bf09328f2597633ee8e2cfa68de (patch)
treebf8dfb9a2860e6096a79c51e7ccbccb7c7d0fe67
parent00cb0a5770529999191fc4484348fe89196de263 (diff)
downloadmplint-31f7c8009e2d6bf09328f2597633ee8e2cfa68de.tar.gz
mplint-31f7c8009e2d6bf09328f2597633ee8e2cfa68de.tar.bz2
mplint-31f7c8009e2d6bf09328f2597633ee8e2cfa68de.tar.xz
mplint-31f7c8009e2d6bf09328f2597633ee8e2cfa68de.zip
Implement simple caching for compiled regular expressions
-rw-r--r--src/stringutils.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/stringutils.cpp b/src/stringutils.cpp
index fc80017..e7c8b5b 100644
--- a/src/stringutils.cpp
+++ b/src/stringutils.cpp
@@ -28,6 +28,7 @@
#include <cstdio>
#include <ctime>
#include <list>
+#include <unordered_map>
#include <sys/stat.h>
@@ -709,16 +710,20 @@ void secureChatCommand(std::string &str)
bool isMatch(const std::string &str,
const std::string &exp)
{
- std::regex regExp(exp);
- return std::regex_match(str, regExp);
+ 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]);
}
bool isMatch(const std::string &str,
const std::string &exp,
std::smatch &m)
{
- std::regex regExp(exp);
- return std::regex_match(str, m, regExp);
+ 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]);
}
bool fileExists(const std::string &name)