diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2018-06-11T14·06+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2018-06-12T15·49+0200 |
commit | 24c68069948681366ff2351dd7400af6e69006d9 (patch) | |
tree | b82b0ab73f4962977cb6a8dc478e36d5ac75c4ef /src/libexpr/eval.cc | |
parent | 6ad0a2f749b4db6b24e8b86625883b0b43ad7ba1 (diff) |
Cache parse trees
This prevents EvalState::resetFileCache() from parsing everything all over again.
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r-- | src/libexpr/eval.cc | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 01658aa25f28..facfddbb5300 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -332,7 +332,6 @@ EvalState::EvalState(const Strings & _searchPath, ref<Store> store) EvalState::~EvalState() { - fileEvalCache.clear(); } @@ -711,7 +710,17 @@ void EvalState::evalFile(const Path & path_, Value & v) } printTalkative("evaluating file '%1%'", path2); - Expr * e = parseExprFromFile(checkSourcePath(path2)); + Expr * e = nullptr; + + auto j = fileParseCache.find(path2); + if (j != fileParseCache.end()) + e = j->second; + + if (!e) + e = parseExprFromFile(checkSourcePath(path2)); + + fileParseCache[path2] = e; + try { eval(e, v); } catch (Error & e) { |