On Sat, Mar 25, 2017 at 12:11:38AM +0100, lemonboy wrote: > Hello hackers, > here's a small patch that makes `string->list' tail recursive, we gain > a small speed up and > one less word allocated for every iteration. > The patch has been made against the chicken-5 branch and should apply > cleanly to the > master branch too.
Hi all, Looks good to me, and should indeed go to master and chicken-5 IMHO. I wasn't quite sure whether this patch qualifies as "trivial", as by our rules for single or double-signoff, so I've attached a signed off copy here. Cheers, Peter
From 837ae626c6f3475330aae8ffa6a4878a8fcedede Mon Sep 17 00:00:00 2001 From: LemonBoy <[email protected]> Date: Sat, 25 Mar 2017 00:04:28 +0100 Subject: [PATCH] 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 <[email protected]> --- library.scm | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/library.scm b/library.scm index 284b653..8a654a0 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) -- 2.1.4
signature.asc
Description: Digital signature
_______________________________________________ Chicken-hackers mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-hackers
