Skip to content

Commit 4d304cd

Browse files
committed
Simplify rb_fields_tbl_copy
Now that ivars are stored in a imemo/fields, we can just clone the fields object.
1 parent ce6e612 commit 4d304cd

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

variable.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4747,22 +4747,18 @@ rb_class_ivar_set(VALUE obj, ID id, VALUE val)
47474747
return !existing;
47484748
}
47494749

4750-
static int
4751-
tbl_copy_i(ID key, VALUE val, st_data_t dest)
4752-
{
4753-
rb_class_ivar_set((VALUE)dest, key, val);
4754-
4755-
return ST_CONTINUE;
4756-
}
4757-
47584750
void
47594751
rb_fields_tbl_copy(VALUE dst, VALUE src)
47604752
{
47614753
RUBY_ASSERT(rb_type(dst) == rb_type(src));
47624754
RUBY_ASSERT(RB_TYPE_P(dst, T_CLASS) || RB_TYPE_P(dst, T_MODULE));
47634755
RUBY_ASSERT(RSHAPE_TYPE_P(RBASIC_SHAPE_ID(dst), SHAPE_ROOT));
47644756

4765-
rb_ivar_foreach(src, tbl_copy_i, dst);
4757+
VALUE fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(src);
4758+
if (fields_obj) {
4759+
RCLASS_WRITABLE_SET_FIELDS_OBJ(dst, rb_imemo_fields_clone(fields_obj));
4760+
RBASIC_SET_SHAPE_ID(dst, RBASIC_SHAPE_ID(src));
4761+
}
47664762
}
47674763

47684764
static rb_const_entry_t *

0 commit comments

Comments
 (0)