]> git.donarmstrong.com Git - lilypond.git/commitdiff
patch::: 1.3.59.uu2
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 13 Jun 2000 18:46:43 +0000 (20:46 +0200)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Tue, 13 Jun 2000 18:46:43 +0000 (20:46 +0200)
1.3.59.hwn1
===========

* Use Scheme_hash_table for identifier Scopes.  Scheme_hash_table is
based on STL and should be faster than hash_table.

18 files changed:
CHANGES
VERSION
flower/dstream.cc
flower/include/dictionary.hh
flower/include/dstream.hh
lily/identifier.cc
lily/include/identifier.hh
lily/include/scm-hash.hh
lily/include/scope.hh
lily/include/translator-group.hh
lily/music-output-def.cc
lily/my-lily-lexer.cc
lily/paper-def.cc
lily/paper-outputter.cc
lily/scm-hash.cc
lily/scope.cc
lily/translator-group.cc
mutopia/J.S.Bach/wtk1-fugue2.ly

diff --git a/CHANGES b/CHANGES
index 1ddcaf682142419246d7e81feb8b4700ba4627fe..7018720bb3eb8e78075ee7b0367f1aed304c4dd4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+1.3.59.hwn1
+===========
+
+* Use Scheme_hash_table for identifier Scopes.  Scheme_hash_table is
+based on STL and should be faster than hash_table.
+
 1.3.58.hwn1
 ===========
 
diff --git a/VERSION b/VERSION
index 1810523f6724d69da94badddaf0ce085814724aa..38595325eaee15f96eecbe5c3a8b46421fec549b 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond
 MAJOR_VERSION=1
 MINOR_VERSION=3
 PATCH_LEVEL=59
-MY_PATCH_LEVEL=uu1
+MY_PATCH_LEVEL=uu2
 
 # use the above to send patches: MY_PATCH_LEVEL is always empty for a
 # released version.
index 46394bf4d53d581657ab7e221cc5bf189935b88f..5834c3a430e63d0fbc8184ef760cc115882e7574 100644 (file)
@@ -7,9 +7,9 @@
 */
 
 #include <fstream.h>
-#include "dictionary-iter.hh"
 #include "dstream.hh"
-
+#include "dictionary-iter.hh"
+#include "dictionary.hh"
 #include "text-db.hh"
 #include "string-convert.hh"
 #include "rational.hh"
@@ -73,6 +73,9 @@ Dstream::identify_as (String name)
 bool
 Dstream::silent_b (String s) const
 {
+  if (!silent_dict_p_)
+    return 0;
+  
   if (!silent_dict_p_->elem_b (s))
     return false;
   return (*silent_dict_p_)[s];
@@ -201,10 +204,7 @@ Dstream::~Dstream()
 void
 Dstream::clear_silence()
 {
-  for (map<String,bool>::iterator ki(silent_dict_p_->begin ());
-       silent_dict_p_->end () != ki; ki++)
-    {
-      (*ki).second = false;
-    }
+  delete silent_dict_p_;
+  silent_dict_p_ = 0;
 }
 
index ab756d99308fa3bcaadf8c4e067083f3c3308316..2f5e5711caaf769228ad2db1802bd9493f1aea12 100644 (file)
@@ -15,9 +15,6 @@
 
 #include <map>
 
-#include "hash-table.hh"
-
-
 unsigned int string_hash (String);
 
 
index 22a31ea798813e9a13a886756c61d1ecc1a8cee0..0f1c10079661d1b9df778c10d8c6ae593a135030 100644 (file)
@@ -29,6 +29,8 @@ const char eol= '\n';
    
    TODO:
    make a baseclass for indentable streams.
+
+   JUNKME
   */
 class Dstream
 {
@@ -39,7 +41,7 @@ class Dstream
   String current_classname_str_;
   void output (String s);
   Dictionary<bool> *silent_dict_p_;
-
+  
 public:
   void clear_silence();
   bool silent_b (String) const;
index 964b33ceebd8c7b9138f61a82eebdf1dda531835..bd3b6b6c2a2935fe379165daea485db9cf3a96c3 100644 (file)
 #include "debug.hh"
 #include "request.hh"
 #include "translator-group.hh"
+#include "ly-smobs.icc"
 
+IMPLEMENT_UNSMOB(Identifier, identifier);
+IMPLEMENT_SMOBS(Identifier);
 
 Identifier::Identifier (int code)
 {
+  self_scm_ = SCM_EOL;
   token_code_i_ = code;
   accessed_b_ = 0;
 }
@@ -30,6 +34,7 @@ Identifier::Identifier (int code)
 Identifier::Identifier (Identifier const&s)
   : Input (s)
 {
+  self_scm_ = SCM_EOL;
   token_code_i_ = s.token_code_i_;
   accessed_b_ = s.accessed_b_;
 }
@@ -178,3 +183,22 @@ DEFAULT_ACCESSOR(Score);
 DEFAULT_ACCESSOR(Midi_def);
 DEFAULT_ACCESSOR(Paper_def);
 
+int
+Identifier::print_smob (SCM s, SCM p, scm_print_state*)
+{
+ return 1;  
+}
+
+SCM
+Identifier::mark_smob (SCM s)
+{
+  return SCM_EOL;
+}
+
+
+
+void
+Identifier::do_smobify_self ()
+{
+  
+}
index 002b935202b0ff1306f340c5c890368c610acaef..718d93d4d08460909b40c55947de98df864c4116 100644 (file)
@@ -8,9 +8,11 @@
 #define IDENTIFIER_HH
 
 #include "lily-proto.hh"
+#include "lily-guile.hh"
 #include "string.hh"
 #include "input.hh"
 #include "virtual-methods.hh"
+#include "smobs.hh"
 
 
 #define DECLARE_TYPE_NAME(Class)
@@ -39,13 +41,15 @@ virtual Class *  access_content_ ## Class (bool) const { error (#Class  + String
    TODO: use SMOBS for the union type, and junk all derived classes.
    */
 struct Identifier : public Input {
+
+  DECLARE_SMOBS;
   bool init_b_;
   bool accessed_b_;
   int token_code_i_;
   Identifier (Identifier const&);    
   Identifier (int code) ;
   virtual ~Identifier() ;
-
+  
 
   void print() const;
   
@@ -94,5 +98,7 @@ DECLARE_ID_CLASS(Request);
 DECLARE_ID_CLASS(Paper_def);
 DECLARE_ID_CLASS(Midi_def);
 
+Identifier * unsmob_identifier (SCM);
+
 #endif // IDENTIFIER_HH
 
index 9b71a51d6e87a8fd44f3b0a3fbe5f7f9faf18eeb..7a903469c1dc537de3010f30c9ea62a520dae09d 100644 (file)
@@ -14,7 +14,6 @@
 #include <map>
 
 #include "lily-guile.hh"
-#include "hash-table.hh"
 #include "smobs.hh"
 
 
index 19f5313536f5a3a784ce6846de0d11061db0e3a8..2fef19f932f2aa53ec53761f630695501536580d 100644 (file)
 #include "lily-proto.hh"
 #include "lily-guile.hh"
 
-class Protected_scm;
+class Scheme_hash_table;
 class Scope {
-  Hash_table<Protected_scm,Identifier*> *id_dict_;
+  Scheme_hash_table *id_dict_;
 public:
+  SCM to_alist () const; 
   bool elem_b (String ) const;
   bool elem_b (SCM s) const;
-  Identifier *&elem (String);
-  Identifier *&elem (SCM s);  
+  Identifier *elem (String) const;
+  Identifier *elem (SCM) const;  
+  void set (String, Identifier *);
   Scope ();
   
   Scope (Scope const &);
   ~Scope ();
   friend class Scope_iter;
 };
-
+#if 0
 class Scope_iter {
   Hash_table_iter<Protected_scm,Identifier*> * iter_;
 public:
@@ -39,5 +41,6 @@ public:
   SCM scm_key () const;
 };
 
+#endif
 #endif /* SCOPE_HH */
 
index e144a3e8e43961cee9e298bd5d2130df0513a0a5..2bfaad8823b449157339d761a81304073448c50b 100644 (file)
@@ -67,7 +67,7 @@ public:
   Translator *get_simple_translator (String) const;
   Translator_group *find_existing_translator_l (String n, String id);
   Translator_group *find_create_translator_l (String n, String id);
-  Link_array<Translator_group> path_to_acceptable_translator (String alias) const;
+  Link_array<Translator_group> path_to_acceptable_translator (String alias, Music_output_def*) const;
 
   Translator_group*get_default_interpreter();
   virtual ~Translator_group ();
index 0805e3c2426d782af210e2cd932ca285ff485788..d891ef9f715285643bdfbd3568c72dbe54e4aab2 100644 (file)
@@ -10,7 +10,7 @@
 #include "debug.hh"
 #include "music-output-def.hh"
 #include "global-translator.hh"
-#include "dictionary-iter.hh"
+
 #include "identifier.hh"
 #include "main.hh"
 #include "lily-guile.hh"
@@ -39,13 +39,6 @@ Music_output_def::Music_output_def (Music_output_def const &s)
 {
   scope_p_ = new Scope (*s.scope_p_);
   translator_p_dict_p_ = new Scope (*s.translator_p_dict_p_);
-  //  default_properties_ = s.default_properties_;
-  
-  for (Scope_iter i (*translator_p_dict_p_);  i.ok (); i++)
-    {
-      Translator * t = i.val ()->access_content_Translator_group (false);
-      t-> output_def_l_ = this;
-    }
 }
 
 void
@@ -56,11 +49,8 @@ Music_output_def::assign_translator (Translator_group*tp)
     {
       tp->warning (_("Interpretation context with empty type"));
     }
-  if (translator_p_dict_p_->elem_b (s))
-    delete translator_p_dict_p_->elem (s);
-  
-  translator_p_dict_p_->elem (s) = new Translator_group_identifier (tp, 0);
-  tp ->output_def_l_ = this;
+  translator_p_dict_p_->set (s, new Translator_group_identifier (tp, 0));
 }
 
 Translator*
@@ -86,6 +76,7 @@ Music_output_def::get_global_translator_p ()
   if (!t)
     error (_f ("can't find `%s' context", "Score"));
   t = t->clone ();
+  t->output_def_l_ = this;
   Global_translator *g = dynamic_cast <Global_translator *> (t);
   t->add_processing ();
   
index a547335081321d302fe8c5342824b5df1568e987..fb238c20246a6619ac26139f5f8d529784575dcf 100644 (file)
@@ -120,14 +120,14 @@ My_lily_lexer::set_identifier (String name_str, Identifier* i, bool )
    
   if  (old)
     {
-      delete old;
+      //      delete old;
     }
   if (lookup_keyword (name_str) >= 0)
     {
       warning (  _f ("Identifier name is a keyword: `%s'", name_str));
     }
   
-  scope_l_arr_.top ()->elem (name_str) = i;
+  scope_l_arr_.top ()->set (name_str, i);
 }
 
 My_lily_lexer::~My_lily_lexer()
index 08adf11220692ddf50464357e0f0f74244354ffb..c32c88f41565526b8e6d0933edd6360f56f6abc9 100644 (file)
@@ -19,7 +19,6 @@
 #include "identifier.hh"
 #include "main.hh"
 #include "scope.hh"
-#include "dictionary-iter.hh"
 #include "file-results.hh" // urg? header_global_p
 #include "paper-outputter.hh"
 #include "paper-stream.hh"
index 4999f0800ecd3d00d1ec653df93e7df729022e3b..92e5180e11546467c87e2cacab913dd27e3c70c4 100644 (file)
@@ -13,7 +13,6 @@
 #include <iostream.h>
 
 #include "dimensions.hh"
-#include "dictionary-iter.hh"
 #include "virtual-methods.hh"
 #include "paper-outputter.hh"
 #include "paper-stream.hh"
@@ -149,25 +148,32 @@ Paper_outputter::dump_scheme (SCM s)
 void
 Paper_outputter::output_scope (Scope *scope, String prefix)
 {
-  for (Scope_iter i (*scope); i.ok (); i++)
+  SCM al = scope->to_alist ();
+  for (SCM s = al ; gh_pair_p (s); s = gh_cdr (s))
     {
-      if (dynamic_cast<String_identifier*> (i.val ()))
-       {
-         String val = *i.val()->access_content_String (false);
+      SCM k = gh_caar (s);
+      SCM v = gh_cdar (s);
+
+      Identifier * id = unsmob_identifier (v);
+      String s = ly_symbol2string (k);
 
-         output_String_def (prefix + i.key (), val);
+      if (dynamic_cast<String_identifier*> (id))
+       {
+         String val = *id->access_content_String (false);
+         
+         output_String_def (prefix + s, val);
        }
-      else if(dynamic_cast<Real_identifier*> (i.val ()))
+      else if(dynamic_cast<Real_identifier*> (id))
        {
-         Real val  = *i.val ()->access_content_Real (false);
+         Real val  = *id->access_content_Real (false);
 
-         output_Real_def (prefix + i.key (), val);       
+         output_Real_def (prefix + s, val);      
        }
-      else if (dynamic_cast<int_identifier*> (i.val ()))
+      else if (dynamic_cast<int_identifier*> (id))
        {
-         int val  = *i.val ()->access_content_int (false);       
+         int val  = *id->access_content_int (false);     
          
-         output_int_def (prefix + i.key (), val);        
+         output_int_def (prefix + s, val);       
        }
     }
 }
index 8a2094b86ee7508b246f70f70417fbf0981bb6ed..08f90c5aa067c4e256c68e3da9510b5bca2e11d0 100644 (file)
@@ -9,7 +9,7 @@
 #include <stdio.h>
 
 #include "scm-hash.hh"
-#include "hash-table-iter.hh"
+
 
 
 Scheme_hash_table::Scheme_hash_table ()
index 917f97344abc93c9e2e6695c80ef1cbaf88fb270..88056b9b8b7e41f852ba06d129c3d3890410d281 100644 (file)
@@ -8,39 +8,32 @@
  */
 
 #include "scope.hh"
-#include "dictionary-iter.hh"
-#include "debug.hh"
 #include "identifier.hh"
-#include "dictionary.hh"
-#include "protected-scm.hh"
+#include "scm-hash.hh"
 
 
 Scope::~Scope ()
 {
-  for (Scope_iter ai (*this); ai.ok(); ai++)
-    delete ai.val ();
   delete id_dict_;
 }
 
 Scope::Scope (Scope const&s)
+  : id_dict_ (new Scheme_hash_table (*s.id_dict_))
 {
+  /*
+    cloning not necessary.
+
   id_dict_ = new Hash_table<Protected_scm,Identifier*> (*s.id_dict_);
   for (Scope_iter ai (s); ai.ok(); ai++)
     {
       id_dict_->elem (ai.scm_key ()) = ai.val ()->clone ();
     }
+  */
 }
 
-unsigned int ly_pscm_hash (Protected_scm s)
-{
-  return ly_scm_hash (s);
-}
-
-
 Scope::Scope ()
 {
-  id_dict_ = new Hash_table<Protected_scm,Identifier*>;
-  id_dict_->hash_func_ = ly_pscm_hash;
+  id_dict_ = new Scheme_hash_table;
 }
 
 bool
@@ -50,57 +43,31 @@ Scope::elem_b (String s) const
 }
 
 
-Identifier *&
-Scope::elem (String s) 
-{
-  return id_dict_->elem (ly_symbol2scm (s.ch_C()));
-}
-
-
-Scope_iter::Scope_iter (Scope const &s)
-{
-  iter_ = new Hash_table_iter<Protected_scm,Identifier*>(*s.id_dict_);
-}
-
-String
-Scope_iter::key () const
-{
-  SCM s= iter_->key ();
-  return ly_symbol2string (s);
-}
-
 bool
 Scope::elem_b (SCM s) const
 {
   return id_dict_->elem_b (s);
 }
-
-Identifier* &
-Scope::elem (SCM s)
-{
-  return id_dict_->elem (s);
-}
-
-SCM
-Scope_iter::scm_key () const
+Identifier*
+Scope::elem (SCM s)const
 {
-  return iter_->key ();
+  return unsmob_identifier  (id_dict_->get (s));
 }
-
-bool
-Scope_iter::ok () const
+Identifier*
+Scope::elem (String s)const
 {
-  return iter_->ok();
+  return elem (ly_symbol2scm (s.ch_C()));
 }
 
 void
-Scope_iter::operator ++(int)
+Scope::set (String s, Identifier * id) 
 {
-  (*iter_) ++;
+  return id_dict_->set (ly_symbol2scm (s.ch_C()),
+                       id->smobify_self());
 }
 
-Identifier*
-Scope_iter::val ()const
+SCM
+Scope::to_alist () const
 {
-  return iter_->val ();
+  return id_dict_->to_alist ();
 }
index d4ac8ff52862595f8bf23dcf1249803345737a34..4a7f6046e7d2c21d1319b17f57991b658b14dee2 100644 (file)
@@ -11,7 +11,6 @@
 #include "translator.hh"
 #include "debug.hh"
 #include "moment.hh"
-#include "dictionary-iter.hh"
 
 #include "killing-cons.tcc"
 
@@ -57,7 +56,7 @@ void
 Translator_group::add_translator (Translator *trans_p)
 {
   trans_p_list_.append (new Killing_cons<Translator> (trans_p,0));
-  
+
   trans_p->daddy_trans_l_ = this;
   trans_p->output_def_l_ = output_def_l_;
   trans_p->add_processing ();
@@ -140,12 +139,12 @@ Translator_group::find_existing_translator_l (String n, String id)
 }
 
 Link_array<Translator_group>
-Translator_group::path_to_acceptable_translator (String type) const
+Translator_group::path_to_acceptable_translator (String type, Music_output_def* odef) const
 {
  Link_array<Translator_group> accepted_arr;
   for (int i=0; i < accepts_str_arr_.size (); i++)
     {
-      Translator *t = output_def_l ()->find_translator_l (accepts_str_arr_[i]);
+      Translator *t = odef->find_translator_l (accepts_str_arr_[i]);
       if (!t || !dynamic_cast <Translator_group *> (t))
        continue;
       accepted_arr.push (dynamic_cast <Translator_group *> (t));
@@ -167,7 +166,7 @@ Translator_group::path_to_acceptable_translator (String type) const
       Translator_group * g = accepted_arr[i];
 
       Link_array<Translator_group> result
-       = g->path_to_acceptable_translator (type);
+       = g->path_to_acceptable_translator (type, odef);
       if (result.size () && result.size () < best_depth)
        {
          result.insert (g,0);
@@ -185,7 +184,8 @@ Translator_group::find_create_translator_l (String n, String id)
   if (existing)
     return existing;
 
-  Link_array<Translator_group> path = path_to_acceptable_translator (n);
+  Link_array<Translator_group> path
+    = path_to_acceptable_translator (n, output_def_l ());
 
   if (path.size ())
     {
@@ -195,6 +195,7 @@ Translator_group::find_create_translator_l (String n, String id)
       for (int i=0; i < path.size (); i++)
        {
          Translator_group * new_group = dynamic_cast<Translator_group*>(path[i]->clone ());
+
          current->add_translator (new_group);
          current = new_group;
        }
index abf6daf7c95ab60dc942e2f31233c3b3cadab86e..0eaea58b382e6fd18484ee756b0a1b904ba9be2c 100644 (file)
@@ -164,14 +164,15 @@ bassdux = \context Voice=three \notes \relative c' {
  
     \notes \context PianoStaff < 
        \context Staff = treble <
-           \key c \minor;
+%          \key c \minor;
+       \key es;
            \dux
            { \comes \bar "|."; }
              \time 4/4;
              \property Score.timeSignatureStyle = "C"
          >
        \context Staff = bass <
-           \key c \minor;
+       \key es;%           \key c \minor;
            \bassdux
        >
     >