aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-07-19 11:48:05 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-07-19 11:48:05 +0000
commit0f827cc6076ae3c395537a0c9bd806b0d42947c2 (patch)
tree13c7e2090562d1e2cb02aade854a7599f4072275
parent2135e7c0417b366b4161d01ebf794d25e96b61ba (diff)
* Prevent repeated wrapping of closed terms
(closed(closed(closed(...)))) since this reduces performance by producing bigger terms and killing caching (which incidentally also prevents useful infinite recursion detection).
-rw-r--r--src/libexpr/nixexpr.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 5c67b74ca..289e923c3 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -233,7 +233,12 @@ Expr substitute(const ATermMap & subs, Expr e)
if (matchVar(e, name)) {
Expr sub = subs.get(name);
- return sub ? makeClosed(sub) : e;
+ Expr wrapped;
+ /* Add a "closed" wrapper around terms that aren't already
+ closed. The check is necessary to prevent repeated
+ wrapping, e.g., closed(closed(closed(...))), which kills
+ caching. */
+ return sub ? (matchClosed(sub, wrapped) ? sub : makeClosed(sub)) : e;
}
/* In case of a function, filter out all variables bound by this