From 706e9bc7983ebb54cfbd7f95b1e98252dfd0d558 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 29 Mar 2018 06:45:17 -0700 Subject: lib: eliminate reduce-left from n-ary math ops. Using reduce-left is inefficient; it conses up a list. We can decimate the stacked arguments without consing. * lib.c (nary_op): Replace reduce_left with iteration. (nary_simple_op): New function, variant of nary_op useable by functions that have a mandatory argument passed separately from the argument list. (minusv, divv): Replace reduce_left with iteration. (maxv, minv): Replace reduce_left with nary_simple_op. (abso_self): New static function. (gcdv, lcmv): Replace reduce_left with nary_op. * lib.h (nary_simple_op): Declared. --- lib.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib.h') diff --git a/lib.h b/lib.h index f5e4194f..f39f075a 100644 --- a/lib.h +++ b/lib.h @@ -661,6 +661,8 @@ val numberp(val num); val nary_op(val self, val (*bfun)(val, val), val (*ufun)(val self, val), struct args *args, val emptyval); +val nary_simple_op(val self, val (*bfun)(val, val), + struct args *args, val emptyval); val plus(val anum, val bnum); val plusv(struct args *); val minus(val anum, val bnum); -- cgit v1.2.3