summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-03-14 23:18:56 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-03-14 23:18:56 -0700
commiteae893a1a2da7a075a7c90b23949dce2f57b2d1b (patch)
treeab7bbf275a1f642d838b508e8e6865d8124fc23c
parenta7323bafa21f8154c2d127c9b66aaa74fc4c1aa7 (diff)
downloadtxr-eae893a1a2da7a075a7c90b23949dce2f57b2d1b.tar.gz
txr-eae893a1a2da7a075a7c90b23949dce2f57b2d1b.tar.bz2
txr-eae893a1a2da7a075a7c90b23949dce2f57b2d1b.zip
append*: save a bit of memory.
* lib.c (lazy_appendv_func, lazy_appendv): Do not allocate a cons cell for maintaining the state. Use the function environment for one of the two state values, and thread the other state value through the initial car contents of each lazy cons cell.
-rw-r--r--lib.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/lib.c b/lib.c
index 6e09308c..10df5305 100644
--- a/lib.c
+++ b/lib.c
@@ -1513,16 +1513,15 @@ val replace_list(val list, val items, val from, val to)
}
}
-static val lazy_appendv_func(val env, val lcons)
+static val lazy_appendv_func(val rl, val lcons)
{
- cons_bind (fl, rl, env);
+ val fl = us_car(lcons);
cons_bind (fe, re, fl);
us_rplaca(lcons, fe);
if (re) {
- us_rplaca(env, re);
- us_rplacd(lcons, make_lazy_cons(us_lcons_fun(lcons)));
+ us_rplacd(lcons, make_lazy_cons_car(us_lcons_fun(lcons), re));
} else if (rl) {
do {
fl = car(rl);
@@ -1531,9 +1530,9 @@ static val lazy_appendv_func(val env, val lcons)
if (fl) {
if (rl) {
- us_rplaca(env, fl);
- us_rplacd(env, rl);
- us_rplacd(lcons, make_lazy_cons(us_lcons_fun(lcons)));
+ val fun = us_lcons_fun(lcons);
+ us_func_set_env(fun, rl);
+ us_rplacd(lcons, make_lazy_cons_car(fun, fl));
} else {
us_rplacd(lcons, fl);
}
@@ -1562,8 +1561,8 @@ val lazy_appendv(struct args *args)
nonempty, nao);
{
- return make_lazy_cons(func_f1(cons(nonempty, args_get_rest(args, index)),
- lazy_appendv_func));
+ return make_lazy_cons_car(func_f1(args_get_rest(args, index),
+ lazy_appendv_func), nonempty);
}
}