~ chicken-core (chicken-5) bc6fe0c6b392ca2066c2d8fde13e1f28c937fc17


commit bc6fe0c6b392ca2066c2d8fde13e1f28c937fc17
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:34:52 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 284b6530..8a654a0d 100644
--- a/library.scm
+++ b/library.scm
@@ -639,15 +639,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