From dfd93790a53f5cf55229441e8f9c857ca866fb56 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 24 Jul 2005 17:08:20 +0000 Subject: [PATCH] * lily/grob.cc (Grob): look properties up directly. * lily/open-type-font.cc (get_indexed_char): cache index -> bbox lookups. * lily/include/box.hh (class Box): smob Box type. --- ChangeLog | 9 +++++- flower/include/string.icc | 7 +++++ flower/string.cc | 6 +--- lily/box.cc | 22 ++++++++++++++ lily/context.cc | 20 ++++++------- lily/grob-property.cc | 29 +------------------ lily/grob.cc | 24 ++++++++++----- lily/include/box.hh | 2 ++ lily/include/open-type-font.hh | 2 ++ lily/open-type-font.cc | 18 +++++++++++- lily/profile.cc | 53 ++++++++++++++++++++++++++++++++++ 11 files changed, 139 insertions(+), 53 deletions(-) create mode 100644 lily/profile.cc diff --git a/ChangeLog b/ChangeLog index 0bd8d57804..982529742f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,13 @@ 2005-07-24 Han-Wen Nienhuys - * lily/smobs.cc (protect_smob): experiment: O(1) GC (un)protection. + * lily/grob.cc (Grob): look properties up directly. + + * lily/open-type-font.cc (get_indexed_char): cache index -> bbox + lookups. + + * lily/include/box.hh (class Box): smob Box type. + + * lily/smobs.cc (protect_smob): O(1) GC (un)protection. * lily/include/smobs.hh (DECLARE_BASE_SMOBS): add methods protect() and unprotect(). Use throughout. diff --git a/flower/include/string.icc b/flower/include/string.icc index 526d7c4eba..158be0c2a5 100644 --- a/flower/include/string.icc +++ b/flower/include/string.icc @@ -17,6 +17,13 @@ to_string (String s) return s; } +INLINE +char const * +String::to_str0 () const +{ + return strh_.to_str0 (); +} + // because char const* also has an operator ==, this is for safety: INLINE bool diff --git a/flower/string.cc b/flower/string.cc index 32ac7fca60..8f34cf44ad 100644 --- a/flower/string.cc +++ b/flower/string.cc @@ -131,11 +131,7 @@ String::to_bytes () const return strh_.to_bytes (); } -char const * -String::to_str0 () const -{ - return strh_.to_str0 (); -} + Byte * String::get_bytes () diff --git a/lily/box.cc b/lily/box.cc index c933c1bc05..b13f4f3420 100644 --- a/lily/box.cc +++ b/lily/box.cc @@ -6,6 +6,8 @@ (c) 1996--2005 Han-Wen Nienhuys */ +#include "ly-smobs.icc" + #include "box.hh" #include "array.hh" @@ -82,3 +84,23 @@ Box::widen (Real x, Real y) interval_a_[X_AXIS].widen (x); interval_a_[Y_AXIS].widen (y); } + + +IMPLEMENT_SIMPLE_SMOBS(Box); +IMPLEMENT_TYPE_P (Box, "ly:box?"); +IMPLEMENT_DEFAULT_EQUAL_P(Box); + +SCM +Box::mark_smob (SCM x) +{ + (void)x; + return SCM_EOL; +} + +int +Box::print_smob (SCM x, SCM p, scm_print_state*) +{ + (void)x; + scm_puts ("#", p); + return 1; +} diff --git a/lily/context.cc b/lily/context.cc index c977cc4e2e..9177616318 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -18,6 +18,8 @@ #include "translator-group.hh" #include "warn.hh" #include "lilypond-key.hh" +#include "profile.hh" + bool Context::is_removable () const @@ -336,6 +338,13 @@ Context::get_default_interpreter () Context * Context::where_defined (SCM sym, SCM *value) const { +#ifndef NDEBUG + if (profile_property_accesses) + { + note_property_access (&context_property_lookup_table, sym); + } +#endif + if (properties_dict ()->try_retrieve (sym, value)) { return (Context *)this; @@ -344,16 +353,6 @@ Context::where_defined (SCM sym, SCM *value) const return (daddy_context_) ? daddy_context_->where_defined (sym, value) : 0; } -SCM context_property_lookup_table; -LY_DEFINE(ly_context_property_lookup_stats, "ly:context-property-lookup-stats", - 0,0,0, (), - "") -{ - return context_property_lookup_table ? context_property_lookup_table - : scm_c_make_hash_table (1); -} - - /* return SCM_EOL when not found. */ @@ -363,7 +362,6 @@ Context::internal_get_property (SCM sym) const #ifndef NDEBUG if (profile_property_accesses) { - extern void note_property_access (SCM *table, SCM sym); note_property_access (&context_property_lookup_table, sym); } #endif diff --git a/lily/grob-property.cc b/lily/grob-property.cc index faa6579444..16fb8be221 100644 --- a/lily/grob-property.cc +++ b/lily/grob-property.cc @@ -16,7 +16,7 @@ #include "misc.hh" #include "item.hh" #include "program-option.hh" - +#include "profile.hh" SCM Grob::get_property_alist_chain (SCM def) const @@ -97,34 +97,7 @@ Grob::internal_set_property (SCM sym, SCM v) //#define PROFILE_PROPERTY_ACCESSES -SCM grob_property_lookup_table; -LY_DEFINE(ly_property_lookup_stats, "ly:grob-property-lookup-stats", - 0,0,0, (), - "") -{ - return grob_property_lookup_table ? grob_property_lookup_table : - scm_c_make_hash_table (1); -} - -void -note_property_access (SCM *table, SCM sym) -{ - /* - Statistics: which properties are looked up? - */ - if (!*table) - *table = scm_permanent_object (scm_c_make_hash_table (259)); - - SCM hashhandle = scm_hashq_get_handle (*table, sym); - if (hashhandle == SCM_BOOL_F) - { - scm_hashq_set_x (*table, sym, scm_from_int (0)); - hashhandle = scm_hashq_get_handle (*table, sym); - } - int count = scm_to_int (scm_cdr (hashhandle)) + 1; - scm_set_cdr_x (hashhandle, scm_from_int (count)); -} SCM diff --git a/lily/grob.cc b/lily/grob.cc index b43ed15409..b60058a1a4 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -70,6 +70,7 @@ Grob::Grob (SCM basicprops, { ((Object_key*)key_)->unprotect (); } + SCM meta = get_property ("meta"); if (scm_is_pair (meta)) { @@ -83,14 +84,23 @@ Grob::Grob (SCM basicprops, creation. Convenient eg. when using \override with StaffSymbol. */ - char const *onames[] = {"X-offset-callbacks", "Y-offset-callbacks"}; - char const *xnames[] = {"X-extent", "Y-extent"}; - char const *enames[] = {"X-extent-callback", "Y-extent-callback"}; + SCM off_callbacks[] = { + get_property ("X-offset-callbacks"), + get_property ("Y-offset-callbacks") + }; + SCM extents[] = { + get_property ("X-extent"), + get_property ("Y-extent") + }; + SCM extent_callbacks[] = { + get_property ("X-extent-callback"), + get_property ("Y-extent-callback") + }; for (int a = X_AXIS; a <= Y_AXIS; a++) { - SCM l = get_property (onames[a]); - + SCM l = off_callbacks[a]; + if (scm_ilength (l) >= 0) { dim_cache_[a].offset_callbacks_ = l; @@ -99,13 +109,13 @@ Grob::Grob (SCM basicprops, else programming_error ("[XY]-offset-callbacks must be a list"); - SCM cb = get_property (enames[a]); + SCM cb = extent_callbacks[a]; if (cb == SCM_BOOL_F) { dim_cache_[a].dimension_ = SCM_BOOL_F; } - SCM xt = get_property (xnames[a]); + SCM xt = extents[a]; if (is_number_pair (xt)) { dim_cache_[a].dimension_ = xt; diff --git a/lily/include/box.hh b/lily/include/box.hh index 55da1fb78d..813e698953 100644 --- a/lily/include/box.hh +++ b/lily/include/box.hh @@ -7,10 +7,12 @@ #include "interval.hh" #include "offset.hh" +#include "smobs.hh" class Box { Interval interval_a_[NO_AXES]; + DECLARE_SIMPLE_SMOBS(Box,); public: Interval &x () {return interval_a_[X_AXIS]; } Interval &y (){ return interval_a_[Y_AXIS]; } diff --git a/lily/include/open-type-font.hh b/lily/include/open-type-font.hh index 02278dbf23..ae90e276db 100644 --- a/lily/include/open-type-font.hh +++ b/lily/include/open-type-font.hh @@ -24,6 +24,8 @@ class Open_type_font : public Font_metric SCM lily_subfonts_; SCM lily_character_table_; SCM lily_global_table_; + SCM lily_index_to_bbox_table_; + Index_to_charcode_map index_to_charcode_map_; Open_type_font (FT_Face); diff --git a/lily/open-type-font.cc b/lily/open-type-font.cc index ddd6b7c80e..5ac1c9c735 100644 --- a/lily/open-type-font.cc +++ b/lily/open-type-font.cc @@ -127,11 +127,14 @@ Open_type_font::Open_type_font (FT_Face face) lily_character_table_ = SCM_EOL; lily_global_table_ = SCM_EOL; lily_subfonts_ = SCM_EOL; - + lily_index_to_bbox_table_ = SCM_EOL; + lily_character_table_ = alist_to_hashq (load_scheme_table ("LILC", face_)); lily_global_table_ = alist_to_hashq (load_scheme_table ("LILY", face_)); lily_subfonts_ = load_scheme_table ("LILF", face_); index_to_charcode_map_ = make_index_to_charcode_map (face_); + + lily_index_to_bbox_table_ = scm_c_make_hash_table (257); } void @@ -140,6 +143,7 @@ Open_type_font::derived_mark () const scm_gc_mark (lily_character_table_); scm_gc_mark (lily_global_table_); scm_gc_mark (lily_subfonts_); + scm_gc_mark (lily_index_to_bbox_table_); } Offset @@ -161,6 +165,14 @@ Open_type_font::attachment_point (String glyph_name) const Box Open_type_font::get_indexed_char (int signed_idx) const { + if (SCM_HASHTABLE_P (lily_index_to_bbox_table_)) + { + SCM box = scm_hashq_ref (lily_index_to_bbox_table_, scm_from_int (signed_idx), SCM_BOOL_F); + Box * box_ptr = Box::unsmob (box); + if (box_ptr) + return *box_ptr; + } + if (SCM_HASHTABLE_P (lily_character_table_)) { const int len = 256; @@ -187,6 +199,10 @@ Open_type_font::get_indexed_char (int signed_idx) const bbox = scm_cdr (bbox); b.scale (point_constant); + + scm_hashq_set_x (lily_index_to_bbox_table_, + scm_from_int (signed_idx), + b.smobbed_copy ()); return b; } } diff --git a/lily/profile.cc b/lily/profile.cc new file mode 100644 index 0000000000..0e986d4d70 --- /dev/null +++ b/lily/profile.cc @@ -0,0 +1,53 @@ +/* + profile.cc -- implement profiling utilities. + + source file of the GNU LilyPond music typesetter + + (c) 2005 Han-Wen Nienhuys + +*/ + +#include "profile.hh" + +void note_property_access (SCM *table, SCM sym); + +SCM context_property_lookup_table; +SCM grob_property_lookup_table; + +LY_DEFINE(ly_context_property_lookup_stats, "ly:context-property-lookup-stats", + 0,0,0, (), + "") +{ + return context_property_lookup_table ? context_property_lookup_table + : scm_c_make_hash_table (1); +} + + + +LY_DEFINE(ly_property_lookup_stats, "ly:grob-property-lookup-stats", + 0,0,0, (), + "") +{ + return grob_property_lookup_table ? grob_property_lookup_table : + scm_c_make_hash_table (1); +} + +void +note_property_access (SCM *table, SCM sym) +{ + /* + Statistics: which properties are looked up? + */ + if (!*table) + *table = scm_permanent_object (scm_c_make_hash_table (259)); + + SCM hashhandle = scm_hashq_get_handle (*table, sym); + if (hashhandle == SCM_BOOL_F) + { + scm_hashq_set_x (*table, sym, scm_from_int (0)); + hashhandle = scm_hashq_get_handle (*table, sym); + } + + int count = scm_to_int (scm_cdr (hashhandle)) + 1; + scm_set_cdr_x (hashhandle, scm_from_int (count)); +} -- 2.39.5