forked from lix-project/lix
* Memory reduction: replaced expensive calls to ATmakeApplList by
ATmakeApplArray, and got rid of ATreverse in substitute().
This commit is contained in:
parent
dc719e6ba5
commit
11ae2d1e7a
|
@ -142,12 +142,12 @@ ATerm bottomupRewrite(TermFun & f, ATerm e)
|
||||||
if (ATgetType(e) == AT_APPL) {
|
if (ATgetType(e) == AT_APPL) {
|
||||||
AFun fun = ATgetAFun(e);
|
AFun fun = ATgetAFun(e);
|
||||||
int arity = ATgetArity(fun);
|
int arity = ATgetArity(fun);
|
||||||
ATermList args = ATempty;
|
ATerm args[arity];
|
||||||
|
|
||||||
for (int i = arity - 1; i >= 0; i--)
|
for (int i = 0; i < arity; ++i)
|
||||||
args = ATinsert(args, bottomupRewrite(f, ATgetArgument(e, i)));
|
args[i] = bottomupRewrite(f, ATgetArgument(e, i));
|
||||||
|
|
||||||
e = (ATerm) ATmakeApplList(fun, args);
|
e = (ATerm) ATmakeApplArray(fun, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (ATgetType(e) == AT_LIST) {
|
else if (ATgetType(e) == AT_LIST) {
|
||||||
|
@ -285,19 +285,24 @@ Expr substitute(const ATermMap & subs, Expr e)
|
||||||
if (ATgetType(e) == AT_APPL) {
|
if (ATgetType(e) == AT_APPL) {
|
||||||
AFun fun = ATgetAFun(e);
|
AFun fun = ATgetAFun(e);
|
||||||
int arity = ATgetArity(fun);
|
int arity = ATgetArity(fun);
|
||||||
ATermList args = ATempty;
|
ATerm args[arity];
|
||||||
|
|
||||||
for (int i = arity - 1; i >= 0; i--)
|
for (int i = 0; i < arity; ++i)
|
||||||
args = ATinsert(args, substitute(subs, ATgetArgument(e, i)));
|
args[i] = substitute(subs, ATgetArgument(e, i));
|
||||||
|
|
||||||
return (ATerm) ATmakeApplList(fun, args);
|
return (ATerm) ATmakeApplArray(fun, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ATgetType(e) == AT_LIST) {
|
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;
|
ATermList out = ATempty;
|
||||||
for (ATermIterator i((ATermList) e); i; ++i)
|
for (unsigned int j = len; j; --j)
|
||||||
out = ATinsert(out, substitute(subs, *i));
|
out = ATinsert(out, es[j - 1]);
|
||||||
return (ATerm) ATreverse(out);
|
return (ATerm) out;
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
|
|
Loading…
Reference in a new issue