From 6dbc6492a97aaf59c8390e4951c0440214db96f1 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 16 May 2023 19:03:22 -0400 Subject: node: Remove costly closure allocation in update/render methods. --- catbird/node.scm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/catbird/node.scm b/catbird/node.scm index bc158a5..b80c45e 100644 --- a/catbird/node.scm +++ b/catbird/node.scm @@ -102,10 +102,16 @@ (define (for-each-child proc node) (for-each proc (children node))) +;; Optimized recursive update that does not allocate a closure. +(define (update-nodes nodes dt) + (unless (null? nodes) + (update/around (car nodes) dt) + (update-nodes (cdr nodes) dt))) + (define-method (update/around (node ) dt) (unless (paused? node) ;; Update children first, recursively. - (for-each-child (lambda (child) (update/around child dt)) node) + (update-nodes (children node) dt) (next-method))) (define-method (tree-in-view? (node )) @@ -114,10 +120,16 @@ (define-method (in-view? (node )) #t) +;; Optimized recursive render that does not allocate a closure. +(define (render-nodes nodes alpha) + (unless (null? nodes) + (render/around (car nodes) alpha) + (render-nodes (cdr nodes) alpha))) + (define-method (render/around (node ) alpha) (when (and (visible? node) (tree-in-view? node)) (next-method) - (for-each-child (lambda (child) (render/around child alpha)) node))) + (render-nodes (children node) alpha))) (define-method (child-ref (parent ) name) (hashq-ref (children-by-name parent) name)) -- cgit v1.2.3