diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-03-31 16:14:32 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-03-31 16:14:32 +0000 |
commit | 55e207b2dc43e426bd0dfbc2065b8853a1fc59b0 (patch) | |
tree | 435a8dd5a321b4ac503e47ef011033d36bc543ab | |
parent | 3d94be61ea562dea2098b6570f711386179913ef (diff) | |
download | guix-55e207b2dc43e426bd0dfbc2065b8853a1fc59b0.tar.gz |
* Cache parse trees to prevent repeated parsing of imported Nix
expressions.
-rw-r--r-- | src/libexpr/eval.cc | 9 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 2 | ||||
-rw-r--r-- | src/libexpr/parser.y | 6 |
3 files changed, 10 insertions, 7 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 0296afe601..b4156ffec1 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -272,7 +272,14 @@ void EvalState::cloneAttrs(Value & src, Value & dst) void EvalState::evalFile(const Path & path, Value & v) { startNest(nest, lvlTalkative, format("evaluating file `%1%'") % path); - Expr e = parseExprFromFile(*this, path); + + Expr e = parseTrees.get(toATerm(path)); + + if (!e) { + e = parseExprFromFile(*this, path); + parseTrees.set(toATerm(path), e); + } + try { eval(e, v); } catch (Error & e) { diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index eba97dd737..7369892fbc 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -135,6 +135,8 @@ private: bool allowUnsafeEquality; + ATermMap parseTrees; + public: EvalState(); diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 2f0c9db3f3..3a56c2627c 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -526,12 +526,6 @@ Expr parseExprFromFile(EvalState & state, Path path) { assert(path[0] == '/'); -#if 0 - /* Perhaps this is already an imploded parse tree? */ - Expr e = ATreadFromNamedFile(path.c_str()); - if (e) return e; -#endif - /* If `path' is a symlink, follow it. This is so that relative path references work. */ struct stat st; |