From: David Kastrup Date: Wed, 21 Mar 2012 18:57:46 +0000 (+0100) Subject: Issue 2425: Don't reload initialization files when processing multiple files X-Git-Tag: release/2.15.35-1~14 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e9f23376b8bac1ae6b776d944469712c983e844c;p=lilypond.git Issue 2425: Don't reload initialization files when processing multiple files This significantly speeds up processing of multiple files per session, but has some more potential for bleedover between files. Bleedover can occur when data structures set up by init.ly (and the loaded files) in the parser module before calling the main file are modified in-place. init.ly caters for the known cases: some hash tables modified by user commands are cleared at the start of a new pass, and output definitions are cloned rather than reused from the first load of init.ly. --- diff --git a/ly/init.ly b/ly/init.ly index 6546ed422a..684ea14e45 100644 --- a/ly/init.ly +++ b/ly/init.ly @@ -6,8 +6,41 @@ \version "2.15.18" -\include "declarations-init.ly" +#(if (not (pair? lilypond-declarations)) + (ly:parser-include-string parser + "\\include \"declarations-init.ly\"")) +%% We need to save the variables of the current module along with +%% their values: functions defined in the module might refer to the +%% variables + +#(if lilypond-declarations + (if (pair? lilypond-declarations) + (begin + (for-each + (lambda (p) + (let ((var (cadr p)) + (val (cddr p))) + (variable-set! var + (if (ly:output-def? val) + (ly:output-def-clone val) + val)) + (module-add! (current-module) (car p) var))) + lilypond-declarations) + (note-names-language parser default-language)) + (module-for-each + (lambda (s v) + (let ((val (variable-ref v))) + (if (not (ly:lily-parser? val)) + (set! lilypond-declarations + (cons + (cons* + s v + (if (ly:output-def? val) + (ly:output-def-clone val) + val)) + lilypond-declarations))))) + (current-module)))) #(ly:set-option 'old-relative #f) #(define toplevel-scores (list)) @@ -19,7 +52,12 @@ #(define expect-error #f) #(define output-empty-score-list #f) #(define output-suffix #f) +#(hash-clear! default-fret-table) +#(hash-clear! chord-shape-table) +#(hash-clear! musicQuotes) + #(use-modules (scm clip-region)) +#(use-modules (srfi srfi-1)) $(if (ly:get-option 'include-settings) (ly:parser-include-string parser diff --git a/scm/lily.scm b/scm/lily.scm index 0c20c148b2..64c403b074 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -845,6 +845,8 @@ PIDs or the number of the process." (dump-profile "lily-run-total" '(0 0) (profile-measurements))) failed)) +(define-public lilypond-declarations '()) + (define (lilypond-file handler file-name) (catch 'ly-file-failed (lambda () (ly:parse-file file-name))