>From 997b45df39535d5f60abdc161e28ee4e01c352e1 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sun, 19 Feb 2012 21:42:34 +0100 Subject: [PATCH 1/2] 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 --- optimizer.scm | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/optimizer.scm b/optimizer.scm index 30e4a2d..b470198 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) -- 1.7.9.1