CVSROOT:        /cvsroot/lilypond
Module name:    lilypond
Branch:         
Changes by:     Han-Wen Nienhuys <[EMAIL PROTECTED]>    05/07/24 17:08:20

Modified files:
        .              : ChangeLog 
        flower         : string.cc 
        flower/include : string.icc 
        lily           : box.cc context.cc grob-property.cc grob.cc 
                         open-type-font.cc 
        lily/include   : box.hh open-type-font.hh 
Added files:
        lily           : profile.cc 

Log message:
        * 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.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/ChangeLog.diff?tr1=1.3920&tr2=1.3921&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/flower/string.cc.diff?tr1=1.51&tr2=1.52&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/flower/include/string.icc.diff?tr1=1.13&tr2=1.14&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/profile.cc?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/box.cc.diff?tr1=1.20&tr2=1.21&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/context.cc.diff?tr1=1.63&tr2=1.64&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/grob-property.cc.diff?tr1=1.29&tr2=1.30&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/grob.cc.diff?tr1=1.136&tr2=1.137&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/open-type-font.cc.diff?tr1=1.38&tr2=1.39&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/include/box.hh.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/lilypond/lilypond/lily/include/open-type-font.hh.diff?tr1=1.18&tr2=1.19&r1=text&r2=text

Patches:
Index: lilypond/ChangeLog
diff -u lilypond/ChangeLog:1.3920 lilypond/ChangeLog:1.3921
--- lilypond/ChangeLog:1.3920   Sun Jul 24 15:30:01 2005
+++ lilypond/ChangeLog  Sun Jul 24 17:08:19 2005
@@ -1,6 +1,13 @@
 2005-07-24  Han-Wen Nienhuys  <[EMAIL PROTECTED]>
 
-       * 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: lilypond/flower/include/string.icc
diff -u lilypond/flower/include/string.icc:1.13 
lilypond/flower/include/string.icc:1.14
--- lilypond/flower/include/string.icc:1.13     Sun May 15 23:44:06 2005
+++ lilypond/flower/include/string.icc  Sun Jul 24 17:08:20 2005
@@ -17,6 +17,13 @@
   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: lilypond/flower/string.cc
diff -u lilypond/flower/string.cc:1.51 lilypond/flower/string.cc:1.52
--- lilypond/flower/string.cc:1.51      Fri May 13 15:45:33 2005
+++ lilypond/flower/string.cc   Sun Jul 24 17:08:20 2005
@@ -131,11 +131,7 @@
   return strh_.to_bytes ();
 }
 
-char const *
-String::to_str0 () const
-{
-  return strh_.to_str0 ();
-}
+
 
 Byte *
 String::get_bytes ()
Index: lilypond/lily/box.cc
diff -u lilypond/lily/box.cc:1.20 lilypond/lily/box.cc:1.21
--- lilypond/lily/box.cc:1.20   Wed Mar 16 19:19:15 2005
+++ lilypond/lily/box.cc        Sun Jul 24 17:08:20 2005
@@ -6,6 +6,8 @@
   (c) 1996--2005 Han-Wen Nienhuys <[EMAIL PROTECTED]>
 */
 
+#include "ly-smobs.icc"
+
 #include "box.hh"
 #include "array.hh"
 
@@ -81,4 +83,24 @@
 {
   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: lilypond/lily/context.cc
diff -u lilypond/lily/context.cc:1.63 lilypond/lily/context.cc:1.64
--- lilypond/lily/context.cc:1.63       Sun Jul 24 15:30:02 2005
+++ lilypond/lily/context.cc    Sun Jul 24 17:08:20 2005
@@ -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 *
 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 @@
   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 @@
 #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: lilypond/lily/grob-property.cc
diff -u lilypond/lily/grob-property.cc:1.29 lilypond/lily/grob-property.cc:1.30
--- lilypond/lily/grob-property.cc:1.29 Sun Jul 24 01:33:35 2005
+++ lilypond/lily/grob-property.cc      Sun Jul 24 17:08:20 2005
@@ -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 @@
 
 //#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: lilypond/lily/grob.cc
diff -u lilypond/lily/grob.cc:1.136 lilypond/lily/grob.cc:1.137
--- lilypond/lily/grob.cc:1.136 Sun Jul 24 15:30:02 2005
+++ lilypond/lily/grob.cc       Sun Jul 24 17:08:20 2005
@@ -70,6 +70,7 @@
     {
       ((Object_key*)key_)->unprotect ();
     }
+  
   SCM meta = get_property ("meta");
   if (scm_is_pair (meta))
     {
@@ -83,14 +84,23 @@
   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 @@
       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: lilypond/lily/include/box.hh
diff -u lilypond/lily/include/box.hh:1.14 lilypond/lily/include/box.hh:1.15
--- lilypond/lily/include/box.hh:1.14   Sun Jul 24 15:39:03 2005
+++ lilypond/lily/include/box.hh        Sun Jul 24 17:08:20 2005
@@ -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: lilypond/lily/include/open-type-font.hh
diff -u lilypond/lily/include/open-type-font.hh:1.18 
lilypond/lily/include/open-type-font.hh:1.19
--- lilypond/lily/include/open-type-font.hh:1.18        Sun May  8 13:17:15 2005
+++ lilypond/lily/include/open-type-font.hh     Sun Jul 24 17:08:20 2005
@@ -24,6 +24,8 @@
   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: lilypond/lily/open-type-font.cc
diff -u lilypond/lily/open-type-font.cc:1.38 
lilypond/lily/open-type-font.cc:1.39
--- lilypond/lily/open-type-font.cc:1.38        Sun May  8 13:17:15 2005
+++ lilypond/lily/open-type-font.cc     Sun Jul 24 17:08:20 2005
@@ -127,11 +127,14 @@
   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 @@
   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 @@
 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 @@
          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;
        }
     }


_______________________________________________
Lilypond-cvs mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-cvs

Reply via email to