From ee7a5648ebcede3c2775d944dd91e8e33dfeabad Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 13 Jun 2000 20:46:43 +0200 Subject: [PATCH] patch::: 1.3.59.uu2 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. --- CHANGES | 6 +++ VERSION | 2 +- flower/dstream.cc | 14 +++---- flower/include/dictionary.hh | 3 -- flower/include/dstream.hh | 4 +- lily/identifier.cc | 24 +++++++++++ lily/include/identifier.hh | 8 +++- lily/include/scm-hash.hh | 1 - lily/include/scope.hh | 13 +++--- lily/include/translator-group.hh | 2 +- lily/music-output-def.cc | 17 ++------ lily/my-lily-lexer.cc | 4 +- lily/paper-def.cc | 1 - lily/paper-outputter.cc | 30 ++++++++------ lily/scm-hash.cc | 2 +- lily/scope.cc | 71 +++++++++----------------------- lily/translator-group.cc | 13 +++--- mutopia/J.S.Bach/wtk1-fugue2.ly | 5 ++- 18 files changed, 111 insertions(+), 109 deletions(-) diff --git a/CHANGES b/CHANGES index 1ddcaf6821..7018720bb3 100644 --- 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 1810523f67..38595325ea 100644 --- 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. diff --git a/flower/dstream.cc b/flower/dstream.cc index 46394bf4d5..5834c3a430 100644 --- a/flower/dstream.cc +++ b/flower/dstream.cc @@ -7,9 +7,9 @@ */ #include -#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::iterator ki(silent_dict_p_->begin ()); - silent_dict_p_->end () != ki; ki++) - { - (*ki).second = false; - } + delete silent_dict_p_; + silent_dict_p_ = 0; } diff --git a/flower/include/dictionary.hh b/flower/include/dictionary.hh index ab756d9930..2f5e5711ca 100644 --- a/flower/include/dictionary.hh +++ b/flower/include/dictionary.hh @@ -15,9 +15,6 @@ #include -#include "hash-table.hh" - - unsigned int string_hash (String); diff --git a/flower/include/dstream.hh b/flower/include/dstream.hh index 22a31ea798..0f1c100796 100644 --- a/flower/include/dstream.hh +++ b/flower/include/dstream.hh @@ -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 *silent_dict_p_; - + public: void clear_silence(); bool silent_b (String) const; diff --git a/lily/identifier.cc b/lily/identifier.cc index 964b33ceeb..bd3b6b6c2a 100644 --- a/lily/identifier.cc +++ b/lily/identifier.cc @@ -19,10 +19,14 @@ #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 () +{ + +} diff --git a/lily/include/identifier.hh b/lily/include/identifier.hh index 002b935202..718d93d4d0 100644 --- a/lily/include/identifier.hh +++ b/lily/include/identifier.hh @@ -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 diff --git a/lily/include/scm-hash.hh b/lily/include/scm-hash.hh index 9b71a51d6e..7a903469c1 100644 --- a/lily/include/scm-hash.hh +++ b/lily/include/scm-hash.hh @@ -14,7 +14,6 @@ #include #include "lily-guile.hh" -#include "hash-table.hh" #include "smobs.hh" diff --git a/lily/include/scope.hh b/lily/include/scope.hh index 19f5313536..2fef19f932 100644 --- a/lily/include/scope.hh +++ b/lily/include/scope.hh @@ -13,21 +13,23 @@ #include "lily-proto.hh" #include "lily-guile.hh" -class Protected_scm; +class Scheme_hash_table; class Scope { - Hash_table *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 * iter_; public: @@ -39,5 +41,6 @@ public: SCM scm_key () const; }; +#endif #endif /* SCOPE_HH */ diff --git a/lily/include/translator-group.hh b/lily/include/translator-group.hh index e144a3e8e4..2bfaad8823 100644 --- a/lily/include/translator-group.hh +++ b/lily/include/translator-group.hh @@ -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 path_to_acceptable_translator (String alias) const; + Link_array path_to_acceptable_translator (String alias, Music_output_def*) const; Translator_group*get_default_interpreter(); virtual ~Translator_group (); diff --git a/lily/music-output-def.cc b/lily/music-output-def.cc index 0805e3c242..d891ef9f71 100644 --- a/lily/music-output-def.cc +++ b/lily/music-output-def.cc @@ -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 (t); t->add_processing (); diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index a547335081..fb238c2024 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -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() diff --git a/lily/paper-def.cc b/lily/paper-def.cc index 08adf11220..c32c88f415 100644 --- a/lily/paper-def.cc +++ b/lily/paper-def.cc @@ -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" diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 4999f0800e..92e5180e11 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -13,7 +13,6 @@ #include #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 (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 (id)) + { + String val = *id->access_content_String (false); + + output_String_def (prefix + s, val); } - else if(dynamic_cast (i.val ())) + else if(dynamic_cast (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 (i.val ())) + else if (dynamic_cast (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); } } } diff --git a/lily/scm-hash.cc b/lily/scm-hash.cc index 8a2094b86e..08f90c5aa0 100644 --- a/lily/scm-hash.cc +++ b/lily/scm-hash.cc @@ -9,7 +9,7 @@ #include #include "scm-hash.hh" -#include "hash-table-iter.hh" + Scheme_hash_table::Scheme_hash_table () diff --git a/lily/scope.cc b/lily/scope.cc index 917f97344a..88056b9b8b 100644 --- a/lily/scope.cc +++ b/lily/scope.cc @@ -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 (*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; - 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(*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 (); } diff --git a/lily/translator-group.cc b/lily/translator-group.cc index d4ac8ff528..4a7f6046e7 100644 --- a/lily/translator-group.cc +++ b/lily/translator-group.cc @@ -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 (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::path_to_acceptable_translator (String type) const +Translator_group::path_to_acceptable_translator (String type, Music_output_def* odef) const { Link_array 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 (t)) continue; accepted_arr.push (dynamic_cast (t)); @@ -167,7 +166,7 @@ Translator_group::path_to_acceptable_translator (String type) const Translator_group * g = accepted_arr[i]; Link_array 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 path = path_to_acceptable_translator (n); + Link_array 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(path[i]->clone ()); + current->add_translator (new_group); current = new_group; } diff --git a/mutopia/J.S.Bach/wtk1-fugue2.ly b/mutopia/J.S.Bach/wtk1-fugue2.ly index abf6daf7c9..0eaea58b38 100644 --- a/mutopia/J.S.Bach/wtk1-fugue2.ly +++ b/mutopia/J.S.Bach/wtk1-fugue2.ly @@ -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 > > -- 2.39.2