From b65f31a95153bdc2a6097784a72f79fd04f3342e Mon Sep 17 00:00:00 2001 From: Francois-Rene Rideau Date: Fri, 5 Jun 2020 19:41:49 +0000 Subject: [PATCH] Inline with-list-builder, second version This version is about 10% faster on my machine. See https://gist.github.com/vyzo/3db10df3a1fd886bbda5d57369455ff6 --- src/std/misc/list.ss | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/std/misc/list.ss b/src/std/misc/list.ss index 60a0006926..602b0db47d 100644 --- a/src/std/misc/list.ss +++ b/src/std/misc/list.ss @@ -161,17 +161,16 @@ (defrules with-list-builder () ((_ (c) body1 body+ ...) (with-list-builder (c _) body1 body+ ...)) ((_ (poke peek) body1 body+ ...) - (let ((head (cons #f '()))) ;; use a traditional implementation of queue as cons of tail and head - (set-car! head head) + (let* ((head [#f]) ;; use a traditional implementation of queue as cons of tail and head + (tail head)) (defrules poke () - ((_ val) (let ((old-tail (car head)) - (new-tail (cons val '()))) - (set-cdr! old-tail new-tail) - (set-car! head new-tail))) + ((_ val) (let (new-tail [val]) + (##set-cdr! tail new-tail) + (set! tail new-tail))) ((_ . _) (error "invalid number of arguments" poke)) (_ (lambda (val) (poke val)))) (defrules peek () - ((_) (cdr head)) + ((_) (##cdr head)) ((_ . _) (error "invalid number of arguments" peek)) (_ (lambda () (peek)))) body1 body+ ... (peek))))