aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-05-02 14:07:28 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-05-02 14:07:28 +0000
commit11ae2d1e7af05c3410a368338c7d13a49c2d2ccd (patch)
treec62be8ea20feea227bfa2050825cbaa09cceb69e /src
parentdc719e6ba57fc877574bd3bc023a25676c555b3c (diff)
* Memory reduction: replaced expensive calls to ATmakeApplList by
ATmakeApplArray, and got rid of ATreverse in substitute().
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/nixexpr.cc27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc
index 05c1ee45c..f88e28289 100644
--- a/src/libexpr/nixexpr.cc
+++ b/src/libexpr/nixexpr.cc
@@ -142,12 +142,12 @@ ATerm bottomupRewrite(TermFun & f, ATerm e)
if (ATgetType(e) == AT_APPL) {
AFun fun = ATgetAFun(e);
int arity = ATgetArity(fun);
- ATermList args = ATempty;
+ ATerm args[arity];
- for (int i = arity - 1; i >= 0; i--)
- args = ATinsert(args, bottomupRewrite(f, ATgetArgument(e, i)));
+ for (int i = 0; i < arity; ++i)
+ args[i] = bottomupRewrite(f, ATgetArgument(e, i));
- e = (ATerm) ATmakeApplList(fun, args);
+ e = (ATerm) ATmakeApplArray(fun, args);
}
else if (ATgetType(e) == AT_LIST) {
@@ -285,19 +285,24 @@ Expr substitute(const ATermMap & subs, Expr e)
if (ATgetType(e) == AT_APPL) {
AFun fun = ATgetAFun(e);
int arity = ATgetArity(fun);
- ATermList args = ATempty;
+ ATerm args[arity];
- for (int i = arity - 1; i >= 0; i--)
- args = ATinsert(args, substitute(subs, ATgetArgument(e, i)));
+ for (int i = 0; i < arity; ++i)
+ args[i] = substitute(subs, ATgetArgument(e, i));
- return (ATerm) ATmakeApplList(fun, args);
+ return (ATerm) ATmakeApplArray(fun, args);
}
if (ATgetType(e) == AT_LIST) {
+ unsigned int len = ATgetLength((ATermList) e);
+ ATerm es[len];
+ ATermIterator i((ATermList) e);
+ for (unsigned int j = 0; i; ++i, ++j)
+ es[j] = substitute(subs, *i);
ATermList out = ATempty;
- for (ATermIterator i((ATermList) e); i; ++i)
- out = ATinsert(out, substitute(subs, *i));
- return (ATerm) ATreverse(out);
+ for (unsigned int j = len; j; --j)
+ out = ATinsert(out, es[j - 1]);
+ return (ATerm) out;
}
return e;