From 33e0a53bd96744a92fef7e364e7625bde57d7699 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 12 Mar 2019 22:37:21 -0700 Subject: lib: introduce new make_lazy_cons variant. * lib.c (make_lazy_cons_car_cdr): New function. (lazy_where_func, lazy_where_hash_func, where): Use make_lazy_cons_car and the new make_lazy_cons_car_cdr instead of two-step construction and initialization with us_rplaca and us_rplacd. * lib.h (make_lazy_cons_car_cdr): Declared. --- lib.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index fd968ab0..d162fe98 100644 --- a/lib.c +++ b/lib.c @@ -3012,6 +3012,16 @@ val make_lazy_cons_car(val func, val car) return obj; } +val make_lazy_cons_car_cdr(val func, val car, val cdr) +{ + val obj = make_obj(); + obj->lc.type = LCONS; + obj->lc.car = car; + obj->lc.cdr = cdr; + obj->lc.func = func; + return obj; +} + void rcyc_cons(val cons) { cons->c.cdr = recycled_conses; @@ -10776,9 +10786,7 @@ static val lazy_where_func(val seq_iter, val lcons) } { - val cell = make_lazy_cons(lcons_fun(lcons)); - us_rplaca(cell, index); - us_rplacd(lcons, cell); + us_rplacd(lcons, make_lazy_cons_car(lcons_fun(lcons), index)); return nil; } } @@ -10801,10 +10809,7 @@ static val lazy_where_hash_func(val hash_iter, val lcons) } { - val cell = make_lazy_cons(us_lcons_fun(lcons)); - us_rplaca(cell, key); - us_rplacd(cell, func); - us_rplacd(lcons, cell); + us_rplacd(lcons, make_lazy_cons_car_cdr(us_lcons_fun(lcons), key, func)); return nil; } } @@ -10828,9 +10833,8 @@ val where(val func, val seq) } { - val cell = make_lazy_cons(func_f1(seq_iter, lazy_where_func)); + val cell = make_lazy_cons_car(func_f1(seq_iter, lazy_where_func), index); si->inf.obj = func; - us_rplaca(cell, index); return cell; } } else { @@ -10847,12 +10851,8 @@ val where(val func, val seq) } } - { - val cell = make_lazy_cons(func_f1(hash_iter, lazy_where_hash_func)); - us_rplaca(cell, key); - us_rplacd(cell, func); - return cell; - } + return make_lazy_cons_car_cdr(func_f1(hash_iter, lazy_where_hash_func), + key, func); } } -- cgit v1.2.3