about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-23T11·16+0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-23T11·19+0000
commitfe95650487d189bae2be198fe2cbbb0cb6c3788f (patch)
tree04108733590ba30df2647886cb36778e44594733
parent3139481822b770a5ad1f81f447ef31ed5446bc72 (diff)
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).
-rw-r--r--src/libexpr/eval.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 59c42d0b0d6e..300e184328cf 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;
 }