From 4ce652640b01c97d4df287cbc0ec6766a1438fd2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 5 Aug 2003 12:29:47 +0000 Subject: [PATCH] * Cache result of fstatePaths(). TODO: do this in fstore.cc. --- src/fix.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/fix.cc b/src/fix.cc index 57cb12630..8f72d531c 100644 --- a/src/fix.cc +++ b/src/fix.cc @@ -9,12 +9,14 @@ typedef ATerm Expr; typedef map NormalForms; +typedef map PkgPaths; typedef map 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()", &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);