]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/grob.cc (Grob): look properties up directly.
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 24 Jul 2005 17:08:20 +0000 (17:08 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 24 Jul 2005 17:08:20 +0000 (17:08 +0000)
* lily/open-type-font.cc (get_indexed_char): cache index -> bbox
lookups.

* lily/include/box.hh (class Box): smob Box type.

ChangeLog
flower/include/string.icc
flower/string.cc
lily/box.cc
lily/context.cc
lily/grob-property.cc
lily/grob.cc
lily/include/box.hh
lily/include/open-type-font.hh
lily/open-type-font.cc
lily/profile.cc [new file with mode: 0644]

index 0bd8d578040f5333256b1b26030ad4c2623e2134..982529742fe4846fc7a84046834e3d6295adf306 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,13 @@
 2005-07-24  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
-       * 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.
index 526d7c4eba9448be4aa5972a5537ce7d7cc63dca..158be0c2a5f62769111791ad335a6789b2480f99 100644 (file)
@@ -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
index 32ac7fca6088bc6fce8b53da4455c7f7a12a20e9..8f34cf44adc5e7cb51a14e8c4a59b3df0c7d0361 100644 (file)
@@ -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 ()
index c933c1bc05fdde4c99e0a19ae435b45e90573f18..b13f4f3420f891ab622f973d63e388b0b947fc6c 100644 (file)
@@ -6,6 +6,8 @@
   (c) 1996--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+#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 ("#<Box>", p);
+  return 1;
+}
index c977cc4e2e814bdb4d19e5cdaad4d12157fef793..9177616318d31aa619180d5fb4471975124b0efb 100644 (file)
@@ -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
index faa65794441239376b4501bc4468b8d1a145ffb5..16fb8be22190dec226f100f017361d2e8101ab98 100644 (file)
@@ -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
index b43ed1540933baa9f742d38d713bff659e064b6d..b60058a1a46d3b3c4aa3c1020afe59715480c308 100644 (file)
@@ -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;
index 55da1fb78ded0bdf58d3bef8467b120eaba21a36..813e6989532adabf155fb02a6848d543fb3e8c1e 100644 (file)
@@ -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]; }
index 02278dbf2337cdebbc739d277a8f7d13b697393f..ae90e276dbb5c6d5c6d94b3f80a2930d2f692979 100644 (file)
@@ -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);
 
index ddd6b7c80e1bda6f9c02cccae821ec3ba5af5130..5ac1c9c73551920caab09a1a037349a2d6442106 100644 (file)
@@ -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 (file)
index 0000000..0e986d4
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+  profile.cc -- implement profiling utilities.
+
+  source file of the GNU LilyPond music typesetter
+
+  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+*/
+
+#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));
+}