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.
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
return strh_.to_bytes ();
}
-char const *
-String::to_str0 () const
-{
- return strh_.to_str0 ();
-}
+
Byte *
String::get_bytes ()
(c) 1996--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
+#include "ly-smobs.icc"
+
#include "box.hh"
#include "array.hh"
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;
+}
#include "translator-group.hh"
#include "warn.hh"
#include "lilypond-key.hh"
+#include "profile.hh"
+
bool
Context::is_removable () const
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;
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.
*/
#ifndef NDEBUG
if (profile_property_accesses)
{
- extern void note_property_access (SCM *table, SCM sym);
note_property_access (&context_property_lookup_table, sym);
}
#endif
#include "misc.hh"
#include "item.hh"
#include "program-option.hh"
-
+#include "profile.hh"
SCM
Grob::get_property_alist_chain (SCM def) const
//#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
{
((Object_key*)key_)->unprotect ();
}
+
SCM meta = get_property ("meta");
if (scm_is_pair (meta))
{
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;
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;
#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]; }
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);
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
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
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;
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;
}
}
--- /dev/null
+/*
+ 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));
+}