diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-01-02 02:43:18 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-01-02 02:43:18 -0800 |
commit | 2a43a5b68507d24e33783996c6a5fa99dd8233a2 (patch) | |
tree | 73a012e7022559727913a13834e1801ed633ab4b /lib.c | |
parent | 6ac45e04ea817dcd6df3a749f523ed1b96ec0118 (diff) | |
download | txr-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.c | 18 |
1 files changed, 7 insertions, 11 deletions
@@ -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)) |