diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-03-15 07:19:58 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-03-15 07:19:58 -0700 |
commit | 050be651f6f2dbe5d71c641b3fcc6e992f658a82 (patch) | |
tree | 02f698aa1f384e4bc94b54f2d1ca85a8b159f9a3 /lib.c | |
parent | 068b0cc761a6f17312057d65804d90f2579a7593 (diff) | |
download | txr-050be651f6f2dbe5d71c641b3fcc6e992f658a82.tar.gz txr-050be651f6f2dbe5d71c641b3fcc6e992f658a82.tar.bz2 txr-050be651f6f2dbe5d71c641b3fcc6e992f658a82.zip |
tuples: eliminate state conses.
* lib.c (tuples_func, tuples): Store the three context items
in the function's env, and the lcons car and cdr, instead
of allocating a two-cons list stored in the env.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -2281,11 +2281,10 @@ val lazy_flatcar(val tree) } -static val tuples_func(val env, val lcons) +static val tuples_func(val n, val lcons) { list_collect_decl (out, ptail); - us_cons_bind (seq_in, envr, env); - us_cons_bind (n, fill, envr); + us_cons_bind (seq_in, fill, lcons); val seq = seq_in; val count; @@ -2296,10 +2295,10 @@ static val tuples_func(val env, val lcons) for (; gt(count, zero); count = minus(count, one)) ptail = list_collect(ptail, fill); - us_rplaca(env, seq); - if (seq) - us_rplacd(lcons, make_lazy_cons(us_lcons_fun(lcons))); + us_rplacd(lcons, make_lazy_cons_car_cdr(us_lcons_fun(lcons), seq, fill)); + else + us_rplacd(lcons, nil); us_rplaca(lcons, make_like(out, seq_in)); return nil; @@ -2312,8 +2311,7 @@ val tuples(val n, val seq, val fill) if (!seq) return nil; - return make_lazy_cons(func_f1(cons(seq, cons(n, fill)), - tuples_func)); + return make_lazy_cons_car_cdr(func_f1(n, tuples_func), seq, fill); } static val partition_by_func(val env, val lcons) |