From 0f827cc6076ae3c395537a0c9bd806b0d42947c2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 19 Jul 2005 11:48:05 +0000 Subject: * 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). --- src/libexpr/nixexpr.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3