aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-09-21 18:22:45 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-09-21 18:22:45 +0200
commite8e1d420f364afbfface61d3f03889e10e6066c9 (patch)
tree2cd1a7637d516eb5d50501a5508231d979096cf7 /src/libexpr/primops.cc
parentcbe0bb29f4531b2cd6b18775018bf030b1a909e3 (diff)
Don't include <regex> in header files
This reduces compilation time by ~15 seconds (CPU time). Issue #4045.
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 7e8526ea1..9cfe3f402 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -3085,17 +3085,25 @@ static RegisterPrimOp primop_hashString({
.fun = prim_hashString,
});
-/* Match a regular expression against a string and return either
- ‘null’ or a list containing substring matches. */
+struct RegexCache
+{
+ std::unordered_map<std::string, std::regex> cache;
+};
+
+std::shared_ptr<RegexCache> makeRegexCache()
+{
+ return std::make_shared<RegexCache>();
+}
+
void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
auto re = state.forceStringNoCtx(*args[0], pos);
try {
- auto regex = state.regexCache.find(re);
- if (regex == state.regexCache.end())
- regex = state.regexCache.emplace(re, std::regex(re, std::regex::extended)).first;
+ auto regex = state.regexCache->cache.find(re);
+ if (regex == state.regexCache->cache.end())
+ regex = state.regexCache->cache.emplace(re, std::regex(re, std::regex::extended)).first;
PathSet context;
const std::string str = state.forceString(*args[1], context, pos);