summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-04-21 23:03:45 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-04-21 23:03:45 -0700
commit962d2abc1ac024a5de5fe9fd92ad5312b1960a08 (patch)
treee593e048130066f01829a59bda93c5660ebadab5 /arith.c
parent5e79646092720733a8cacf9121bf6fbbbd87425a (diff)
downloadtxr-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.c35
1 files 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)