diff options
author | David Thompson <dthompson2@worcester.edu> | 2023-05-16 19:03:22 -0400 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2023-05-16 19:03:22 -0400 |
commit | 6dbc6492a97aaf59c8390e4951c0440214db96f1 (patch) | |
tree | 5301ac03fb8578726c31748af3f0a14faff6dc96 | |
parent | 1f70403184fd59028a55e430299cc927ee705ce9 (diff) |
node: Remove costly closure allocation in update/render methods.
-rw-r--r-- | catbird/node.scm | 16 |
1 files 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 <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 <node>)) @@ -114,10 +120,16 @@ (define-method (in-view? (node <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 <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 <node>) name) (hashq-ref (children-by-name parent) name)) |