From f50e40f2917b974fac93b368e0546ad99e629a8e Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 25 May 2023 08:42:45 +0900 Subject: [PATCH] mruby-struct/struct.c: use `mrb_ary_set` to simplify the code We don't need to do `mrb_struct_modify()` and calling write barriers by ourselves for the small performance issue. --- mrbgems/mruby-struct/src/struct.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 98171755a..f0d3d5edc 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -158,18 +158,9 @@ static mrb_value mrb_struct_set_m(mrb_state *mrb, mrb_value obj) { mrb_int i = mrb_integer(mrb_proc_cfunc_env_get(mrb, 0)); - mrb_value *ptr; mrb_value val = mrb_get_arg1(mrb); - mrb_struct_modify(mrb, obj); - ptr = RSTRUCT_PTR(obj); - if (ptr == NULL || i >= RSTRUCT_LEN(obj)) { - mrb_ary_set(mrb, obj, i, val); - } - else { - ptr[i] = val; - mrb_field_write_barrier_value(mrb, mrb_basic_ptr(obj), val); - } + mrb_ary_set(mrb, obj, i, val); return val; } @@ -443,23 +434,14 @@ mrb_struct_aset_sym(mrb_state *mrb, mrb_value s, mrb_sym id, mrb_value val) { mrb_value members; const mrb_value *ptr_members; - mrb_int i, len, plen; + mrb_int i, len; members = struct_members(mrb, s); len = RARRAY_LEN(members); - plen = RSTRUCT_LEN(s); ptr_members = RARRAY_PTR(members); for (i=0; i