builtins.cache: Cache regular expressions

The evaluator was spending about 1% of its time compiling a small
number of regexes over and over again.
This commit is contained in:
Eelco Dolstra
2020-03-04 11:44:33 +01:00
parent d700eecea9
commit 401b5bc541
2 changed files with 9 additions and 3 deletions
+4
View File
@@ -114,6 +114,9 @@ private:
/* Cache used by checkSourcePath(). */
std::unordered_map<Path, Path> resolvedPaths;
/* Cache used by prim_match(). */
std::unordered_map<std::string, std::regex> regexCache;
public:
EvalState(const Strings & _searchPath, ref<Store> store);
@@ -314,6 +317,7 @@ private:
friend struct ExprOpConcatLists;
friend struct ExprSelect;
friend void prim_getAttr(EvalState & state, const Pos & pos, Value * * args, Value & v);
friend void prim_match(EvalState & state, const Pos & pos, Value * * args, Value & v);
};