diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2020-04-21 23:03:45 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2020-04-21 23:03:45 -0700 |
commit | 962d2abc1ac024a5de5fe9fd92ad5312b1960a08 (patch) | |
tree | e593e048130066f01829a59bda93c5660ebadab5 /arith.c | |
parent | 5e79646092720733a8cacf9121bf6fbbbd87425a (diff) | |
download | txr-962d2abc1ac024a5de5fe9fd92ad5312b1960a08.tar.gz txr-962d2abc1ac024a5de5fe9fd92ad5312b1960a08.tar.bz2 txr-962d2abc1ac024a5de5fe9fd92ad5312b1960a08.zip |
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.
Diffstat (limited to 'arith.c')
-rw-r--r-- | arith.c | 35 |
1 files changed, 25 insertions, 10 deletions
@@ -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) |