@@ -150,6 +150,71 @@ inline op type_check(out INT, in PMC, in PMC) :base_core {
150
150
}
151
151
152
152
153
+ /*
154
+
155
+ =item publish_type_check_cache(WHAT, type_list)
156
+
157
+ Publishes a type check cache, to be stored in the S-Table.
158
+
159
+ =cut
160
+
161
+ */
162
+ inline op publish_type_check_cache(in PMC, in PMC) :base_core {
163
+ if ($1->vtable->base_type == ro_id) {
164
+ STable *target_st = STABLE($1);
165
+ INTVAL items = VTABLE_elements(interp, $2);
166
+ if (items > 0) {
167
+ PMC **cache = mem_sys_allocate(sizeof(PMC *) * items);
168
+ INTVAL i;
169
+ for (i = 0; i < items; i++)
170
+ cache[i] = VTABLE_get_pmc_keyed_int(interp, $2, i);
171
+ target_st->type_check_cache = cache;
172
+ target_st->type_check_cache_length = items;
173
+ }
174
+ else {
175
+ target_st->type_check_cache = NULL;
176
+ target_st->type_check_cache_length = 0;
177
+ }
178
+ }
179
+ else {
180
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
181
+ "First argument to publish_type_check_cache must be a RakudoObject");
182
+ }
183
+ }
184
+
185
+
186
+ /*
187
+
188
+ =item publish_method_cache(WHAT, method_cache_hash)
189
+
190
+ Publishes a method dispatch cache - essentially, a set of name to code object
191
+ mappings.
192
+
193
+ =cut
194
+
195
+ */
196
+ inline op publish_method_cache(in PMC, in PMC) :base_core {
197
+ if ($1->vtable->base_type == ro_id) {
198
+ /* We copy the cache items to a Parrot hash to avoid making
199
+ * calls into the language's own hash implementation every
200
+ * time, which may be far more costly. */
201
+ STable *target_st = STABLE($1);
202
+ PMC *cache = pmc_new(interp, enum_class_Hash);
203
+ PMC *iter = VTABLE_get_iter(interp, $2);
204
+ while (VTABLE_get_bool(interp, iter)) {
205
+ STRING *name = VTABLE_shift_string(interp, iter);
206
+ PMC *meth = VTABLE_get_pmc_keyed_str(interp, $2, name);
207
+ VTABLE_set_pmc_keyed_str(interp, cache, name, meth);
208
+ }
209
+ target_st->method_cache = cache;
210
+ }
211
+ else {
212
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
213
+ "First argument to publish_method_cache must be a RakudoObject");
214
+ }
215
+ }
216
+
217
+
153
218
/*
154
219
155
220
=item repr_unbox_str()
0 commit comments