From 42e68d71cfa149be195ddf8fce2f6e3b78f7d66a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 2 Jan 2018 02:43:18 -0800 Subject: eliminate cdr_l use from implementation of last. * lib.c (lastcons): Return value is just the last cons rather than a loc. The only caller of this function is last. (last): Adapt to the new lastcons. --- lib.c | 18 +++++++----------- lib.h | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib.c b/lib.c index a48fb78a..fe8efbb6 100644 --- a/lib.c +++ b/lib.c @@ -664,26 +664,22 @@ loc term(loc head) return head; } -loc lastcons(val list) +val lastcons(val list) { - loc ret = nulloc; - + val ret; gc_hint(list); - while (consp(cdr(list))) { - ret = cdr_l(list); - list = deref(ret); - } + for (ret = nil; consp(list); list = cdr(list)) + ret = list; + return ret; } val last(val seq, val n) { if (null_or_missing_p(n)) { - if (listp(seq)) { - loc p = lastcons(seq); - return nullocp(p) ? seq : deref(p); - } + if (listp(seq)) + return lastcons(seq); return sub(seq, negone, t); } else { if (listp(seq)) diff --git a/lib.h b/lib.h index 6ba0140c..f38314dc 100644 --- a/lib.h +++ b/lib.h @@ -537,7 +537,7 @@ val listref(val list, val ind); loc listref_l(val list, val ind); loc tail(val cons); loc term(loc head); -loc lastcons(val list); +val lastcons(val list); val last(val list, val n); val nthlast(val pos, val list); val nthcdr(val pos, val list); -- cgit v1.2.3