~ chicken-core (chicken-5) 2e667a10aa8092c77b42082dc1ad88e868d08b80
commit 2e667a10aa8092c77b42082dc1ad88e868d08b80 Author: LemonBoy <thatlemon@gmail.com> AuthorDate: Sat Mar 25 00:04:28 2017 +0100 Commit: Evan Hanson <evhan@foldling.org> CommitDate: Sun Mar 26 10:52:53 2017 +1300 Rewrite string->list to be tail-recursive. This way we allocate one less word per iteration. A run of chicken-benchmarks shows a (very) small speed-up. Signed-off-by: Peter Bex <peter@more-magic.net> Signed-off-by: Evan Hanson <evhan@foldling.org> diff --git a/library.scm b/library.scm index 9bf84e61..09f9dd15 100644 --- a/library.scm +++ b/library.scm @@ -525,15 +525,14 @@ EOF (##sys#check-char c 'make-string) c ) ) ) ) -(define string->list - (lambda (s) - (##sys#check-string s 'string->list) - (let ((len (##core#inline "C_block_size" s))) - (let loop ((i 0)) - (if (fx>= i len) - '() - (cons (##core#inline "C_subchar" s i) - (loop (fx+ i 1)) ) ) ) ) ) ) +(define (string->list s) + (##sys#check-string s 'string->list) + (let ((len (##sys#size s))) + (let loop ((i (fx- len 1)) (ls '())) + (if (fx< i 0) + ls + (loop (fx- i 1) + (cons (##core#inline "C_subchar" s i) ls)))))) (define ##sys#string->list string->list)Trap