]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 2669: Avoid recreating notename hashes from alists unnecessarily.
authorDavid Kastrup <dak@gnu.org>
Mon, 16 Jul 2012 17:48:01 +0000 (19:48 +0200)
committerDavid Kastrup <dak@gnu.org>
Fri, 20 Jul 2012 05:57:42 +0000 (07:57 +0200)
lily/include/lily-lexer.hh
lily/lexer.ll
lily/lily-lexer.cc
lily/lily-parser-scheme.cc
lily/parser.yy

index 9a48e3b8e90196b931f7776580a03df37db69c7f..e078c9edc394a02b26ade5b66236f11d419197ac 100644 (file)
@@ -92,12 +92,12 @@ public:
   SCM lookup_identifier (string s);
   SCM lookup_identifier_symbol (SCM s);
   void push_extra_token (int token_type, SCM scm = SCM_UNDEFINED);
-  void push_chord_state (SCM tab);
+  void push_chord_state (SCM alist);
   void push_figuredbass_state ();
   void push_lyric_state ();
   void push_initial_state ();
   void push_markup_state ();
-  void push_note_state (SCM tab);
+  void push_note_state (SCM alist);
   void pop_state ();
   void LexerError (char const *);
   void LexerWarning (char const *);
index afb881f2b8f370e3d2afbc87f744517be2c44281..07bb33c6f7187979356d7e6ffac05cca3ba095a5 100644 (file)
@@ -799,9 +799,13 @@ Lily_lexer::push_extra_token (int token_type, SCM scm)
 }
 
 void
-Lily_lexer::push_chord_state (SCM tab)
+Lily_lexer::push_chord_state (SCM alist)
 {
-       pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
+       SCM p = scm_assq (alist, pitchname_tab_stack_);
+
+       if (scm_is_false (p))
+               p = scm_cons (alist, alist_to_hashq (alist));
+       pitchname_tab_stack_ = scm_cons (p, pitchname_tab_stack_);
        yy_push_state (chords);
 }
 
@@ -830,9 +834,13 @@ Lily_lexer::push_markup_state ()
 }
 
 void
-Lily_lexer::push_note_state (SCM tab)
+Lily_lexer::push_note_state (SCM alist)
 {
-       pitchname_tab_stack_ = scm_cons (tab, pitchname_tab_stack_);
+       SCM p = scm_assq (alist, pitchname_tab_stack_);
+
+       if (scm_is_false (p))
+               p = scm_cons (alist, alist_to_hashq (alist));
+       pitchname_tab_stack_ = scm_cons (p, pitchname_tab_stack_);
        yy_push_state (notes);
 }
 
@@ -952,7 +960,7 @@ Lily_lexer::scan_bare_word (string str)
        if ((YYSTATE == notes) || (YYSTATE == chords)) {
                SCM handle = SCM_BOOL_F;
                if (scm_is_pair (pitchname_tab_stack_))
-                       handle = scm_hashq_get_handle (scm_car (pitchname_tab_stack_), sym);
+                       handle = scm_hashq_get_handle (scm_cdar (pitchname_tab_stack_), sym);
                
                if (scm_is_pair (handle)) {
                        yylval.scm = scm_cdr (handle);
index 1bbc5b81674187e813d3613cb8bb205a0465db46..71533da70097be00cee89644726d26e5d2e21d7e 100644 (file)
@@ -101,7 +101,7 @@ Lily_lexer::Lily_lexer (Sources *sources, Lily_parser *parser)
   smobify_self ();
 
   add_scope (ly_make_module (false));
-  push_note_state (scm_c_make_hash_table (0));
+  push_note_state (SCM_EOL);
   chordmodifier_tab_ = scm_make_vector (scm_from_int (1), SCM_EOL);
 }
 
@@ -134,7 +134,7 @@ Lily_lexer::Lily_lexer (Lily_lexer const &src, Lily_parser *parser)
     }
 
   scopes_ = scopes;
-  push_note_state (scm_c_make_hash_table (0));
+  push_note_state (SCM_EOL);
 }
 
 Lily_lexer::~Lily_lexer ()
index 5281f7e2a741c3b8867816ea0ec995afcbb0606a..059cac3149d23b150b2e9f1164f6ac03e96713c3 100644 (file)
@@ -272,7 +272,7 @@ LY_DEFINE (ly_parser_set_note_names, "ly:parser-set-note-names",
   if (p->lexer_->is_note_state ())
     {
       p->lexer_->pop_state ();
-      p->lexer_->push_note_state (alist_to_hashq (names));
+      p->lexer_->push_note_state (names);
     }
 
   return SCM_UNSPECIFIED;
index 98ee4ef7028ca97aae685601af97b5d5ccd27eb6..a9b73280f41e0ce15435c3101e344bb84fc3534c 100644 (file)
@@ -565,7 +565,7 @@ start_symbol:
        lilypond
        | EMBEDDED_LILY {
                SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
-               parser->lexer_->push_note_state (alist_to_hashq (nn));
+               parser->lexer_->push_note_state (nn);
        } embedded_lilypond {
                parser->lexer_->pop_state ();
                parser->lexer_->set_identifier (ly_symbol2scm ("parseStringResult"), $3);
@@ -1855,14 +1855,14 @@ mode_changed_music:
 mode_changing_head:
        NOTEMODE {
                SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
-               parser->lexer_->push_note_state (alist_to_hashq (nn));
+               parser->lexer_->push_note_state (nn);
 
                $$ = ly_symbol2scm ("notes");
        }
        | DRUMMODE
                {
                SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
-               parser->lexer_->push_note_state (alist_to_hashq (nn));
+               parser->lexer_->push_note_state (nn);
 
                $$ = ly_symbol2scm ("drums");
        }
@@ -1875,7 +1875,7 @@ mode_changing_head:
                SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
                parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
                nn = parser->lexer_->lookup_identifier ("pitchnames");
-               parser->lexer_->push_chord_state (alist_to_hashq (nn));
+               parser->lexer_->push_chord_state (nn);
                $$ = ly_symbol2scm ("chords");
 
        }
@@ -1888,7 +1888,7 @@ mode_changing_head:
 mode_changing_head_with_context:
        DRUMS {
                SCM nn = parser->lexer_->lookup_identifier ("drumPitchNames");
-               parser->lexer_->push_note_state (alist_to_hashq (nn));
+               parser->lexer_->push_note_state (nn);
 
                $$ = ly_symbol2scm ("DrumStaff");
        }
@@ -1901,7 +1901,7 @@ mode_changing_head_with_context:
                SCM nn = parser->lexer_->lookup_identifier ("chordmodifiers");
                parser->lexer_->chordmodifier_tab_ = alist_to_hashq (nn);
                nn = parser->lexer_->lookup_identifier ("pitchnames");
-               parser->lexer_->push_chord_state (alist_to_hashq (nn));
+               parser->lexer_->push_chord_state (nn);
                $$ = ly_symbol2scm ("ChordNames");
        }
        | LYRICS
@@ -3183,7 +3183,7 @@ simple_markup:
        }
        | SCORE {
                SCM nn = parser->lexer_->lookup_identifier ("pitchnames");
-               parser->lexer_->push_note_state (alist_to_hashq (nn));
+               parser->lexer_->push_note_state (nn);
        } '{' score_body '}' {
                Score * sc = $4;
                $$ = scm_list_2 (ly_lily_module_constant ("score-markup"), sc->self_scm ());