diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 01658aa25..facfddbb5 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -332,7 +332,6 @@ EvalState::EvalState(const Strings & _searchPath, ref 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) { diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 146f21255..d0f298e16 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -90,6 +90,14 @@ public: private: SrcToStore srcToStore; + /* A cache from path names to parse trees. */ +#if HAVE_BOEHMGC + typedef std::map, traceable_allocator > > FileParseCache; +#else + typedef std::map FileParseCache; +#endif + FileParseCache fileParseCache; + /* A cache from path names to values. */ #if HAVE_BOEHMGC typedef std::map, traceable_allocator > > FileEvalCache;