From 7dacbdb97be0ed3240c4936ff702fc53e35a4381 Mon Sep 17 00:00:00 2001 From: Keith OHara Date: Sat, 27 Dec 2014 17:13:57 -0800 Subject: [PATCH] auto-beam engraver: memory efficiency The old code was tail-recursive modulo cons, but Guile did not seem to recognise that and did not optimize the recursion away. --- scm/auto-beam.scm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scm/auto-beam.scm b/scm/auto-beam.scm index 6191017dfe..9ba08705ef 100644 --- a/scm/auto-beam.scm +++ b/scm/auto-beam.scm @@ -38,12 +38,12 @@ (let ((value (ly:context-property context name))) (if (not (null? value)) value default))) - (define (ending-moments group-list start-beat base-length) - (if (null? group-list) - '() - (let ((new-start (+ start-beat (car group-list)))) - (cons (* new-start base-length) - (ending-moments (cdr group-list) new-start base-length))))) + (define (ending-moments group-list base-length) + (let ((beat 0)) + (map-in-order (lambda (x) + (set! beat (+ beat x)) + (* base-length beat)) + group-list))) (define (larger-setting type sorted-alist) (assoc type sorted-alist <=)) @@ -64,7 +64,7 @@ (time-signature-fraction (get 'timeSignatureFraction '(4 . 4))) (beat-structure (get 'beatStructure '(1 1 1 1))) - (beat-endings (ending-moments beat-structure 0 base-length)) + (beat-endings (ending-moments beat-structure base-length)) (exceptions (sort (map (lambda (a) (if (pair? (car a)) @@ -95,7 +95,7 @@ type)) (exception-moments (and exception-grouping (ending-moments - exception-grouping 0 grouping-moment)))) + exception-grouping grouping-moment)))) (if (= dir START) ;; Start rules -- #t if beam is allowed to start -- 2.39.5