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 Remove the value associated with KEY, and return it. The result is
64 that a next call will yield SCM_EOL (and not the underlying
68 Grob::remove_grob_property (const char* key)
70 SCM val = get_grob_property (key);
72 set_grob_property (key, SCM_EOL);
78 Grob::get_property_alist_chain (SCM def) const
80 #ifndef HASHING_FOR_MUTABLE_PROPS
81 return scm_list_n (mutable_property_alist_,
82 immutable_property_alist_,
86 SCM chain = gh_list (immutable_property_alist_, def, SCM_UNDEFINED);
87 SCM * velts = SCM_VELTS (mutable_property_alist_);
88 int l = SCM_VECTOR_LENGTH(mutable_property_alist_);
89 for (int i = 0; i < l; i++)
91 if (gh_pair_p (velts[i]))
92 chain = gh_cons ( velts[i], chain);
102 This special add_thing routine is slightly more efficient than
104 set_prop (name,cons (thing, get_prop (name)))
106 since it can reuse the handle returned by scm_assq().
109 Grob::add_to_list_property (SCM sym, SCM thing)
112 #ifndef HASHING_FOR_MUTABLE_PROPS
113 = scm_sloppy_assq (sym, mutable_property_alist_)
115 = scm_hashq_get_handle (mutable_property_alist_, sym);
118 if (handle != SCM_BOOL_F)
120 gh_set_cdr_x (handle, gh_cons (thing, gh_cdr (handle)));
125 There is no mutable prop yet, so create an entry, and put it in front of the
128 handle = scm_sloppy_assq (sym, immutable_property_alist_);
129 SCM tail = (handle != SCM_BOOL_F) ? gh_cdr(handle) : SCM_EOL;
130 SCM val = gh_cons (thing, tail);
131 #ifndef HASHING_FOR_MUTABLE_PROPS
132 mutable_property_alist_ = gh_cons (gh_cons (sym, val),
133 mutable_property_alist_);
135 scm_hashq_set_x (mutable_property_alist_, sym, val);
141 extern void check_interfaces_for_property (Grob const *me, SCM sym);
144 Grob::internal_set_grob_property (SCM s, SCM v)
147 Perhaps we simply do the assq_set, but what the heck.
153 if (internal_type_checking_global_b)
155 assert (type_check_assignment (s, v, ly_symbol2scm ("backend-type?")));
156 check_interfaces_for_property(this, s);
160 #ifndef HASHING_FOR_MUTABLE_PROPS
161 mutable_property_alist_ = scm_assq_set_x (mutable_property_alist_, s, v);
163 scm_hashq_set_x (mutable_property_alist_, s, v);
169 Grob::internal_get_grob_property (SCM sym) const
171 #ifndef HASHING_FOR_MUTABLE_PROPS
172 SCM s = scm_sloppy_assq (sym, mutable_property_alist_);
176 if (mutable_property_alist_ == SCM_EOL)
179 SCM s = scm_hashq_ref (mutable_property_alist_, sym, SCM_EOL);
184 s = scm_sloppy_assq (sym, immutable_property_alist_);
187 if (internal_type_checking_global_b && gh_pair_p (s))
189 assert (type_check_assignment (sym, gh_cdr (s), ly_symbol2scm ("backend-type?")));
190 check_interfaces_for_property(this, sym);
194 return (s == SCM_BOOL_F) ? SCM_EOL : ly_cdr (s);
198 Grob::substitute_mutable_properties (SCM crit, SCM orig)
200 set_break_subsititution(crit);
201 #ifndef HASHING_FOR_MUTABLE_PROPS
202 mutable_property_alist_ = substitute_mutable_property_alist (orig);
206 mutable_property_alist_ = SCM_EOL;
210 SCM * src_elts = SCM_VELTS (orig);
211 SCM * dest_elts = SCM_VELTS (mutable_property_alist_);
212 unsigned int l = SCM_VECTOR_LENGTH(mutable_property_alist_);
213 assert (l == SCM_VECTOR_LENGTH(orig));
214 for (unsigned int i = 0; i < l; i++)
216 dest_elts[i] = substitute_mutable_property_alist (src_elts[i]);
225 return immutable_property_alist_ != SCM_EOL;