|
28 | 28 | AREF_HASH_THRESHOLD = 10
|
29 | 29 | };
|
30 | 30 |
|
31 |
| -const rb_iseq_t *rb_method_for_self_aref(VALUE name, VALUE arg, const struct rb_builtin_function *func); |
32 |
| -const rb_iseq_t *rb_method_for_self_aset(VALUE name, VALUE arg, const struct rb_builtin_function *func); |
33 |
| - |
34 | 31 | VALUE rb_cStruct;
|
35 | 32 | static ID id_members, id_back_members, id_keyword_init;
|
36 | 33 |
|
@@ -229,32 +226,6 @@ rb_struct_getmember(VALUE obj, ID id)
|
229 | 226 | UNREACHABLE_RETURN(Qnil);
|
230 | 227 | }
|
231 | 228 |
|
232 |
| -static VALUE rb_struct_ref0(VALUE obj) {return RSTRUCT_GET(obj, 0);} |
233 |
| -static VALUE rb_struct_ref1(VALUE obj) {return RSTRUCT_GET(obj, 1);} |
234 |
| -static VALUE rb_struct_ref2(VALUE obj) {return RSTRUCT_GET(obj, 2);} |
235 |
| -static VALUE rb_struct_ref3(VALUE obj) {return RSTRUCT_GET(obj, 3);} |
236 |
| -static VALUE rb_struct_ref4(VALUE obj) {return RSTRUCT_GET(obj, 4);} |
237 |
| -static VALUE rb_struct_ref5(VALUE obj) {return RSTRUCT_GET(obj, 5);} |
238 |
| -static VALUE rb_struct_ref6(VALUE obj) {return RSTRUCT_GET(obj, 6);} |
239 |
| -static VALUE rb_struct_ref7(VALUE obj) {return RSTRUCT_GET(obj, 7);} |
240 |
| -static VALUE rb_struct_ref8(VALUE obj) {return RSTRUCT_GET(obj, 8);} |
241 |
| -static VALUE rb_struct_ref9(VALUE obj) {return RSTRUCT_GET(obj, 9);} |
242 |
| - |
243 |
| -#define N_REF_FUNC numberof(ref_func) |
244 |
| - |
245 |
| -static VALUE (*const ref_func[])(VALUE) = { |
246 |
| - rb_struct_ref0, |
247 |
| - rb_struct_ref1, |
248 |
| - rb_struct_ref2, |
249 |
| - rb_struct_ref3, |
250 |
| - rb_struct_ref4, |
251 |
| - rb_struct_ref5, |
252 |
| - rb_struct_ref6, |
253 |
| - rb_struct_ref7, |
254 |
| - rb_struct_ref8, |
255 |
| - rb_struct_ref9, |
256 |
| -}; |
257 |
| - |
258 | 229 | static void
|
259 | 230 | rb_struct_modify(VALUE s)
|
260 | 231 | {
|
@@ -300,42 +271,16 @@ struct_pos_num(VALUE s, VALUE idx)
|
300 | 271 | return i;
|
301 | 272 | }
|
302 | 273 |
|
303 |
| -static VALUE |
304 |
| -opt_struct_aref(rb_execution_context_t *ec, VALUE self, VALUE idx) |
305 |
| -{ |
306 |
| - long i = struct_pos_num(self, idx); |
307 |
| - return RSTRUCT_GET(self, i); |
308 |
| -} |
309 |
| - |
310 |
| -static VALUE |
311 |
| -opt_struct_aset(rb_execution_context_t *ec, VALUE self, VALUE val, VALUE idx) |
312 |
| -{ |
313 |
| - long i = struct_pos_num(self, idx); |
314 |
| - rb_struct_modify(self); |
315 |
| - RSTRUCT_SET(self, i, val); |
316 |
| - return val; |
317 |
| -} |
318 |
| - |
319 |
| -static const struct rb_builtin_function struct_aref_builtin = |
320 |
| - RB_BUILTIN_FUNCTION(0, struct_aref, opt_struct_aref, 1, 0); |
321 |
| -static const struct rb_builtin_function struct_aset_builtin = |
322 |
| - RB_BUILTIN_FUNCTION(1, struct_aref, opt_struct_aset, 2, 0); |
323 |
| - |
324 | 274 | static void
|
325 | 275 | define_aref_method(VALUE nstr, VALUE name, VALUE off)
|
326 | 276 | {
|
327 |
| - const rb_iseq_t *iseq = rb_method_for_self_aref(name, off, &struct_aref_builtin); |
328 |
| - iseq->body->builtin_inline_p = true; |
329 |
| - |
330 |
| - rb_add_method_iseq(nstr, SYM2ID(name), iseq, NULL, METHOD_VISI_PUBLIC); |
| 277 | + rb_add_method_optimized(nstr, SYM2ID(name), OPTIMIZED_METHOD_TYPE_STRUCT_AREF, FIX2UINT(off), METHOD_VISI_PUBLIC); |
331 | 278 | }
|
332 | 279 |
|
333 | 280 | static void
|
334 | 281 | define_aset_method(VALUE nstr, VALUE name, VALUE off)
|
335 | 282 | {
|
336 |
| - const rb_iseq_t *iseq = rb_method_for_self_aset(name, off, &struct_aset_builtin); |
337 |
| - |
338 |
| - rb_add_method_iseq(nstr, SYM2ID(name), iseq, NULL, METHOD_VISI_PUBLIC); |
| 283 | + rb_add_method_optimized(nstr, SYM2ID(name), OPTIMIZED_METHOD_TYPE_STRUCT_ASET, FIX2UINT(off), METHOD_VISI_PUBLIC); |
339 | 284 | }
|
340 | 285 |
|
341 | 286 | static VALUE
|
@@ -386,13 +331,8 @@ setup_struct(VALUE nstr, VALUE members)
|
386 | 331 | ID id = SYM2ID(sym);
|
387 | 332 | VALUE off = LONG2NUM(i);
|
388 | 333 |
|
389 |
| - if (i < N_REF_FUNC) { |
390 |
| - rb_define_method_id(nstr, id, ref_func[i], 0); |
391 |
| - } |
392 |
| - else { |
393 |
| - define_aref_method(nstr, sym, off); |
394 |
| - } |
395 |
| - define_aset_method(nstr, ID2SYM(rb_id_attrset(id)), off); |
| 334 | + define_aref_method(nstr, sym, off); |
| 335 | + define_aset_method(nstr, ID2SYM(rb_id_attrset(id)), off); |
396 | 336 | }
|
397 | 337 |
|
398 | 338 | return nstr;
|
@@ -844,7 +784,7 @@ rb_struct_alloc(VALUE klass, VALUE values)
|
844 | 784 | VALUE
|
845 | 785 | rb_struct_new(VALUE klass, ...)
|
846 | 786 | {
|
847 |
| - VALUE tmpargs[N_REF_FUNC], *mem = tmpargs; |
| 787 | + VALUE tmpargs[16], *mem = tmpargs; |
848 | 788 | int size, i;
|
849 | 789 | va_list args;
|
850 | 790 |
|
|
0 commit comments