2 Implement storage and manipulation of grob properties.
9 #include "input-smob.hh"
11 #include "group-interface.hh"
13 #include "paper-score.hh"
14 #include "paper-def.hh"
23 HASHING_FOR_MUTABLE_PROPS:
46 Hashing doesn't improve the result of grob property lookup, at least
47 not with naive hashing. It is possible that the overhead of the
48 scm_hash* functions take too much time. One way to solve this is by
49 using vector accesses directly, and precompute the hashvalues, similar
50 to CACHE_SYMBOLS. That option could only cause slowdowns if the hash
51 tables produces weird cache-line trashing.
53 Second option: we could index immutable props in a hash tab as
54 well. This only takes space, since they are immutable no updates are
55 needed. This does take a lot of space, since we must duplicate the
56 alists (but not the entries).
60 // #define HASHING_FOR_MUTABLE_PROPS
63 Grob::get_property_alist_chain (SCM def) const
65 #ifndef HASHING_FOR_MUTABLE_PROPS
66 return scm_list_n (mutable_property_alist_,
67 immutable_property_alist_,
71 SCM chain = gh_list (immutable_property_alist_, def, SCM_UNDEFINED);
72 SCM * velts = SCM_VELTS (mutable_property_alist_);
73 int l = SCM_VECTOR_LENGTH(mutable_property_alist_);
74 for (int i = 0; i < l; i++)
76 if (gh_pair_p (velts[i]))
77 chain = gh_cons ( velts[i], chain);
87 This special add_thing routine is slightly more efficient than
89 set_prop (name,cons (thing, get_prop (name)))
91 since it can reuse the handle returned by scm_assq().
94 Grob::add_to_list_property (SCM sym, SCM thing)
97 #ifndef HASHING_FOR_MUTABLE_PROPS
98 = scm_sloppy_assq (sym, mutable_property_alist_)
100 = scm_hashq_get_handle (mutable_property_alist_, sym);
103 if (handle != SCM_BOOL_F)
105 gh_set_cdr_x (handle, gh_cons (thing, gh_cdr (handle)));
110 There is no mutable prop yet, so create an entry, and put it in front of the
113 handle = scm_sloppy_assq (sym, immutable_property_alist_);
114 SCM tail = (handle != SCM_BOOL_F) ? gh_cdr(handle) : SCM_EOL;
115 SCM val = gh_cons (thing, tail);
116 #ifndef HASHING_FOR_MUTABLE_PROPS
117 mutable_property_alist_ = gh_cons (gh_cons (sym, val),
118 mutable_property_alist_);
120 scm_hashq_set_x (mutable_property_alist_, sym, val);
126 extern void check_interfaces_for_property (Grob const *me, SCM sym);
129 Grob::internal_set_grob_property (SCM s, SCM v)
132 Perhaps we simply do the assq_set, but what the heck.
138 if (internal_type_checking_global_b)
140 assert (type_check_assignment (s, v, ly_symbol2scm ("backend-type?")));
141 check_interfaces_for_property(this, s);
145 #ifndef HASHING_FOR_MUTABLE_PROPS
146 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, s, v);
148 scm_hashq_set_x (mutable_property_alist_, s, v);
154 Grob::internal_get_grob_property (SCM sym) const
156 #ifndef HASHING_FOR_MUTABLE_PROPS
157 SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
161 if (mutable_property_alist_ == SCM_EOL)
164 SCM s = scm_hashq_ref (mutable_property_alist_, sym, SCM_EOL);
169 s = scm_sloppy_assq (sym, immutable_property_alist_);
172 if (internal_type_checking_global_b && gh_pair_p (s))
174 assert (type_check_assignment (sym, gh_cdr (s), ly_symbol2scm ("backend-type?")));
175 check_interfaces_for_property(this, sym);
179 return (s == SCM_BOOL_F) ? SCM_EOL : ly_cdr (s);
183 Grob::substitute_mutable_properties (SCM crit, SCM orig)
185 set_break_subsititution(crit);
186 #ifndef HASHING_FOR_MUTABLE_PROPS
187 mutable_property_alist_ = substitute_mutable_property_alist (orig);
191 mutable_property_alist_ = SCM_EOL;
195 SCM * src_elts = SCM_VELTS (orig);
196 SCM * dest_elts = SCM_VELTS (mutable_property_alist_);
197 unsigned int l = SCM_VECTOR_LENGTH(mutable_property_alist_);
198 assert (l == SCM_VECTOR_LENGTH(orig));
199 for (unsigned int i = 0; i < l; i++)
201 dest_elts[i] = substitute_mutable_property_alist (src_elts[i]);
210 return immutable_property_alist_ != SCM_EOL;