From fe95650487d189bae2be198fe2cbbb0cb6c3788f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 23 Oct 2013 11:16:46 +0000 Subject: [PATCH] Memoize evalFile() lookups under both the original and resolved name Previously we only used the resolved name, causing repeated resolution (e.g. /dir to /dir/default.nix). --- src/libexpr/eval.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 59c42d0b0..300e18432 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -436,10 +436,14 @@ Value * ExprPath::maybeThunk(EvalState & state, Env & env) void EvalState::evalFile(const Path & path, Value & v) { - Path path2 = resolveExprPath(path); + FileEvalCache::iterator i; + if ((i = fileEvalCache.find(path)) != fileEvalCache.end()) { + v = i->second; + return; + } - FileEvalCache::iterator i = fileEvalCache.find(path2); - if (i != fileEvalCache.end()) { + Path path2 = resolveExprPath(path); + if ((i = fileEvalCache.find(path2)) != fileEvalCache.end()) { v = i->second; return; } @@ -452,8 +456,9 @@ void EvalState::evalFile(const Path & path, Value & v) addErrorPrefix(e, "while evaluating the file `%1%':\n", path2); throw; } + fileEvalCache[path2] = v; - //if (path != path2) fileEvalCache[path2] = v; + if (path != path2) fileEvalCache[path] = v; }