diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-03-15 06:06:25 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-03-15 06:06:25 -0700 |
commit | 10b17a4563985a76c9d107cba4264f3327786856 (patch) | |
tree | 236012bfdee3bef2d1b728b482ed4c0f7257dc72 | |
parent | eae893a1a2da7a075a7c90b23949dce2f57b2d1b (diff) | |
download | txr-10b17a4563985a76c9d107cba4264f3327786856.tar.gz txr-10b17a4563985a76c9d107cba4264f3327786856.tar.bz2 txr-10b17a4563985a76c9d107cba4264f3327786856.zip |
flatten*: use lcons for threading state.
* lib.c (lazy_flatten_func, lazy_flatten): Do not allocate a
cons to hold the traversal state. In fact, the environment of
the function is not used at all; the lcons car and cdr are
used to propagate the state.
-rw-r--r-- | lib.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -2195,16 +2195,16 @@ static val lazy_flatten_scan(val list, val *escape) static val lazy_flatten_func(val env, val lcons) { - us_cons_bind (list, escape, env); + us_cons_bind (list, escape, lcons); val atom = car(list); val next = lazy_flatten_scan(cdr(list), &escape); us_rplaca(lcons, atom); - us_rplaca(env, next); - us_rplacd(env, escape); if (next) - us_rplacd(lcons, make_lazy_cons(us_lcons_fun(lcons))); + us_rplacd(lcons, make_lazy_cons_car_cdr(us_lcons_fun(lcons), next, escape)); + else + us_rplacd(lcons, nil); return nil; } @@ -2220,7 +2220,8 @@ val lazy_flatten(val list) if (!next) return nil; - return make_lazy_cons(func_f1(cons(next, escape), lazy_flatten_func)); + return make_lazy_cons_car_cdr(func_f1(nil, lazy_flatten_func), + next, escape); } } |