From 962d2abc1ac024a5de5fe9fd92ad5312b1960a08 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 21 Apr 2020 23:03:45 -0700 Subject: Reduce consing in /= function. * arith.c (numneqv): Do not unconditionally cons all the arguments into a list. If the arguments structure has no trailing list, then just loop over the arguments in the arg array. Only cons all the arguments into a list if there is a trailing list. --- arith.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/arith.c b/arith.c index 88e6db13..91f65d03 100644 --- a/arith.c +++ b/arith.c @@ -4387,20 +4387,35 @@ val numeqv(val first, struct args *rest) val numneqv(struct args *args) { - val i, j; - val list = args_get_list(args); + if (!args->list) { + cnum i, j, n = args->fill; + + if (n == 1) { + (void) unary_arith(lit("/="), args->arg[0]); + return t; + } + + for (i = 0; i < n; i++) + for (j = i + 1; j < n; j++) + if (numeq(args->arg[i], args->arg[j])) + return nil; - if (list && !cdr(list)) { - (void) unary_arith(lit("/="), car(list)); return t; - } + } else { + val i, j; + val list = args_get_list(args); - for (i = list; i; i = cdr(i)) - for (j = cdr(i); j; j = cdr(j)) - if (numeq(car(i), car(j))) - return nil; + if (list && !cdr(list)) { + (void) unary_arith(lit("/="), car(list)); + return t; + } - return t; + for (i = list; i; i = cdr(i)) + for (j = cdr(i); j; j = cdr(j)) + if (numeq(car(i), car(j))) + return nil; + return t; + } } static val sumv(struct args *nlist, val keyfun) -- cgit v1.2.3