diff options
-rw-r--r-- | src/stringutils.cpp | 13 |
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) |