about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-08-05T12·29+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-08-05T12·29+0000
commit4ce652640b01c97d4df287cbc0ec6766a1438fd2 (patch)
tree830e7126ce764a5f9712c3bd1bfa297b780815e0
parentfd30f52cfca861d109652b6ad5a533e5c108f3e9 (diff)
* Cache result of fstatePaths(). TODO: do this in fstore.cc.
-rw-r--r--src/fix.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/fix.cc b/src/fix.cc
index 57cb12630901..8f72d531c8c7 100644
--- a/src/fix.cc
+++ b/src/fix.cc
@@ -9,12 +9,14 @@
 typedef ATerm Expr;
 
 typedef map<ATerm, ATerm> NormalForms;
+typedef map<FSId, Strings> PkgPaths;
 typedef map<FSId, Hash> PkgHashes;
 
 struct EvalState 
 {
     Strings searchDirs;
     NormalForms normalForms;
+    PkgPaths pkgPaths;
     PkgHashes pkgHashes; /* normalised package hashes */
 };
 
@@ -106,7 +108,20 @@ static Expr substExprMany(ATermList formals, ATermList args, Expr body)
 }
 
 
-Hash hashPackage(EvalState & state, FState fs)
+static Strings fstatePathsCached(EvalState & state, const FSId & id)
+{
+    PkgPaths::iterator i = state.pkgPaths.find(id);
+    if (i != state.pkgPaths.end())
+        return i->second;
+    else {
+        Strings paths = fstatePaths(id);
+        state.pkgPaths[id] = paths;
+        return paths;
+    }
+}
+
+
+static Hash hashPackage(EvalState & state, FState fs)
 {
     if (fs.type == FState::fsDerive) {
         for (FSIds::iterator i = fs.derive.inputs.begin();
@@ -214,7 +229,7 @@ static Expr evalExpr2(EvalState & state, Expr e)
 
             if (ATmatch(value, "FSId(<str>)", &s1)) {
                 FSId id = parseHash(s1);
-                Strings paths = fstatePaths(id);
+                Strings paths = fstatePathsCached(state, id);
                 if (paths.size() != 1) abort();
                 string path = *(paths.begin());
                 fs.derive.inputs.push_back(id);