summaryrefslogtreecommitdiffstats
path: root/lib.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-01-02 02:43:18 -0800
committerKaz Kylheku <kaz@kylheku.com>2018-01-02 02:43:18 -0800
commit2a43a5b68507d24e33783996c6a5fa99dd8233a2 (patch)
tree73a012e7022559727913a13834e1801ed633ab4b /lib.c
parent6ac45e04ea817dcd6df3a749f523ed1b96ec0118 (diff)
downloadtxr-2a43a5b68507d24e33783996c6a5fa99dd8233a2.tar.gz
txr-2a43a5b68507d24e33783996c6a5fa99dd8233a2.tar.bz2
txr-2a43a5b68507d24e33783996c6a5fa99dd8233a2.zip
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.
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c18
1 files changed, 7 insertions, 11 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))