From ceff5513bb6b309d892ff58149ce16f527ce0011 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 22 Aug 2021 02:04:01 -0700 Subject: sub-list: better handling of from value of t. * lib.c (sub_list): If from is t, then just return nil. Do not reset it to nil in this case. After this we know from is not nil; we don't have to check for this inside one loop. That loop was wastefully iterating over the list in the from == nil case only to calculate nil. --- lib.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index 68f95d01..628ed06e 100644 --- a/lib.c +++ b/lib.c @@ -2399,13 +2399,11 @@ val sub_list(val list, val from, val to) { val len = nil; - if (!list) + if (!list || from == t) return nil; if (null_or_missing_p(from)) from = zero; - else if (from == t) - from = nil; else if (minusp(from)) { from = plus(from, len = length(list)); if (to == zero) @@ -2425,7 +2423,7 @@ val sub_list(val list, val from, val to) val i; for (i = zero; list; list = cdr(list), i = plus(i, one)) { - if (from && ge(i, from)) + if (ge(i, from)) break; } return list; -- cgit v1.2.3