~ chicken-core (chicken-5) a0b8cc9a654357119ba89d9cc566c41debcda6ec


commit a0b8cc9a654357119ba89d9cc566c41debcda6ec
Author:     Peter Bex <peter.bex@xs4all.nl>
AuthorDate: Sun Feb 19 21:42:34 2012 +0100
Commit:     felix <felix@call-with-current-continuation.org>
CommitDate: Sat Feb 25 11:50:08 2012 +0100

    Use a hand-rolled loop in WALK-GENERIC; this saves us having to traverse the list a second time in the slow EVERY function and a recursive MAP that checks its arguments all the time. It's called a lot of times with small lists, so this adds up
    
    Signed-off-by: felix <felix@call-with-current-continuation.org>

diff --git a/optimizer.scm b/optimizer.scm
index 30e4a2d8..b4701980 100644
--- a/optimizer.scm
+++ b/optimizer.scm
@@ -500,11 +500,17 @@
 	  (else (walk-generic n class params subs fids gae #f)) ) ) )
     
     (define (walk-generic n class params subs fids gae invgae)
-      (let ((subs2 (map (cut walk <> fids gae) subs)))
-	(when invgae (invalidate-gae! gae))
-	(if (every eq? subs subs2)
-	    n
-	    (make-node class params subs2) ) ) )
+      (let lp ((same? #t)
+               (subs subs)
+               (subs2 '()))
+        (cond ((null? subs)
+               (when invgae (invalidate-gae! gae))
+               ;; Create new node if walk made changes, otherwise original node
+               (if same? n (make-node class params (reverse subs2))))
+              (else
+               (let ((sub2 (walk (car subs) fids gae)))
+                 (lp (and same? (eq? sub2 (car subs)))
+                     (cdr subs) (cons sub2 subs2)))) ) ))
 
     (if (perform-pre-optimization! node db)
 	(values node #t)
Trap