diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-03-18 22:50:45 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-03-18 22:50:45 -0700 |
commit | b80a900ed15ac03e4f63922ed61554978fb605e2 (patch) | |
tree | 42cefc688167df51da15720f59f826c202647e28 /lib.c | |
parent | 7e2d1ec815c6eb6670381c1b2aabfea57003c529 (diff) | |
download | txr-b80a900ed15ac03e4f63922ed61554978fb605e2.tar.gz txr-b80a900ed15ac03e4f63922ed61554978fb605e2.tar.bz2 txr-b80a900ed15ac03e4f63922ed61554978fb605e2.zip |
partition*: optimization.
* lib.c (partition_star_func, partition_star): Eliminate
state cons. Eliminate wasteful cons updating and destructuring
in loop.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 22 |
1 files changed, 8 insertions, 14 deletions
@@ -2510,14 +2510,13 @@ val split_star(val seq, val indices) return partition_split_common(seq, indices, split_star_func); } -static val partition_star_func(val env, val lcons) +static val partition_star_func(val base, val lcons) { + us_cons_bind (seq, indices, lcons); + val fun = us_lcons_fun(lcons); val len = nil; for (;;) { - us_cons_bind (seq, indices_base, env); - us_cons_bind (indices, base, indices_base); - if (indices) { val raw_index = pop(&indices); val index = if3((!opt_compat || opt_compat > 170) && minusp(raw_index), @@ -2536,21 +2535,16 @@ static val partition_star_func(val env, val lcons) pop(&indices); } - us_rplaca(env, seq); - us_rplaca(indices_base, indices); - us_rplacd(indices_base, base); - if (!first) continue; - us_rplaca(lcons, first); - - if (seq) - us_rplacd(lcons, make_lazy_cons(us_lcons_fun(lcons))); + us_rplacd(lcons, if2(seq, make_lazy_cons_car_cdr(fun, seq, indices))); } else { us_rplaca(lcons, seq); + us_rplacd(lcons, nil); } + us_func_set_env(fun, base); break; } @@ -2590,8 +2584,8 @@ val partition_star(val seq, val indices) if (!indices) return cons(seq, nil); - return make_lazy_cons(func_f1(cons(seq, cons(indices, base)), - partition_star_func)); + return make_lazy_cons_car_cdr(func_f1(base, partition_star_func), + seq, indices); } } |