@@ -147,56 +147,46 @@ rb_imemo_fields_new_complex(VALUE klass, size_t capa)
147147 return imemo_fields_new_complex (klass , capa );
148148}
149149
150- static int
151- imemo_fields_trigger_wb_i (st_data_t key , st_data_t value , st_data_t arg )
152- {
153- VALUE field_obj = (VALUE )arg ;
154- RB_OBJ_WRITTEN (field_obj , Qundef , (VALUE )value );
155- return ST_CONTINUE ;
156- }
157-
158- static int
159- imemo_fields_complex_wb_i (st_data_t key , st_data_t value , st_data_t arg )
160- {
161- RB_OBJ_WRITTEN ((VALUE )arg , Qundef , (VALUE )value );
162- return ST_CONTINUE ;
163- }
164-
165150VALUE
166151rb_imemo_fields_new_complex_tbl (VALUE klass , st_table * tbl )
167152{
168153 VALUE fields = imemo_fields_new (klass , sizeof (struct rb_fields ));
169154 IMEMO_OBJ_FIELDS (fields )-> as .complex .table = tbl ;
170- st_foreach ( tbl , imemo_fields_trigger_wb_i , ( st_data_t ) fields );
155+ rb_gc_writebarrier_remember ( fields );
171156 return fields ;
172157}
173158
159+ VALUE
160+ rb_imemo_fields_clone2 (VALUE fields_obj , size_t capa )
161+ {
162+ shape_id_t shape_id = RBASIC_SHAPE_ID (fields_obj );
163+ RUBY_ASSERT (!rb_shape_too_complex_p (shape_id ));
164+
165+ VALUE clone = imemo_fields_new (CLASS_OF (fields_obj ), capa );
166+ VALUE * fields = rb_imemo_fields_ptr (clone );
167+ attr_index_t fields_count = RSHAPE_LEN (shape_id );
168+ MEMCPY (fields , rb_imemo_fields_ptr (fields_obj ), VALUE , fields_count );
169+ RBASIC_SET_SHAPE_ID (clone , shape_id );
170+ rb_gc_writebarrier_remember (clone );
171+
172+ return clone ;
173+ }
174+
174175VALUE
175176rb_imemo_fields_clone (VALUE fields_obj )
176177{
177178 shape_id_t shape_id = RBASIC_SHAPE_ID (fields_obj );
178- VALUE clone ;
179179
180180 if (rb_shape_too_complex_p (shape_id )) {
181- clone = rb_imemo_fields_new_complex (CLASS_OF (fields_obj ), 0 );
181+ VALUE clone = rb_imemo_fields_new_complex (CLASS_OF (fields_obj ), 0 );
182182 RBASIC_SET_SHAPE_ID (clone , shape_id );
183183 st_table * src_table = rb_imemo_fields_complex_tbl (fields_obj );
184184 st_table * dest_table = rb_imemo_fields_complex_tbl (clone );
185185 st_replace (dest_table , src_table );
186- st_foreach (dest_table , imemo_fields_complex_wb_i , (st_data_t )clone );
187- }
188- else {
189- clone = imemo_fields_new (CLASS_OF (fields_obj ), RSHAPE_CAPACITY (shape_id ));
190- RBASIC_SET_SHAPE_ID (clone , shape_id );
191- VALUE * fields = rb_imemo_fields_ptr (clone );
192- attr_index_t fields_count = RSHAPE_LEN (shape_id );
193- MEMCPY (fields , rb_imemo_fields_ptr (fields_obj ), VALUE , fields_count );
194- for (attr_index_t i = 0 ; i < fields_count ; i ++ ) {
195- RB_OBJ_WRITTEN (clone , Qundef , fields [i ]);
196- }
186+ rb_gc_writebarrier_remember (clone );
187+ return clone ;
197188 }
198-
199- return clone ;
189+ return rb_imemo_fields_clone2 (fields_obj , RSHAPE_CAPACITY (shape_id ));
200190}
201191
202192void
0 commit comments