aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/primops.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-03-04 13:58:42 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-03-04 13:58:42 +0100
commit73b6d87e17bbe3c8612af2b9f369d92d3726efbe (patch)
tree8b2b9e76744746122fcea962dd9d98075061d0b0 /src/libexpr/primops.cc
parentf443d5ca19f07153af930686dd7aec44b88f16fd (diff)
parentd37dc71e3cf077fa5d24a9bf8395deae21cc4410 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r--src/libexpr/primops.cc8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index af6c91954..083caf04a 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -1812,19 +1812,21 @@ static void prim_hashString(EvalState & state, const Pos & pos, Value * * args,
/* Match a regular expression against a string and return either
‘null’ or a list containing substring matches. */
-static void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
+void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
auto re = state.forceStringNoCtx(*args[0], pos);
try {
- std::regex regex(re, std::regex::extended);
+ auto regex = state.regexCache.find(re);
+ if (regex == state.regexCache.end())
+ regex = state.regexCache.emplace(re, std::regex(re, std::regex::extended)).first;
PathSet context;
const std::string str = state.forceString(*args[1], context, pos);
std::smatch match;
- if (!std::regex_match(str, match, regex)) {
+ if (!std::regex_match(str, match, regex->second)) {
mkNull(v);
return;
}