Skip to content

Commit 1055d42

Browse files
committed
Avoid creating the fields_obj just to freeze the class
1 parent c7ddb43 commit 1055d42

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

variable.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,13 +2031,17 @@ rb_vm_set_ivar_id(VALUE obj, ID id, VALUE val)
20312031
bool
20322032
rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id)
20332033
{
2034-
if (rb_obj_shape_id(obj) == shape_id) {
2034+
shape_id_t old_shape_id = rb_obj_shape_id(obj);
2035+
if (old_shape_id == shape_id) {
20352036
return false;
20362037
}
20372038

20382039
#if SHAPE_IN_BASIC_FLAGS
20392040
if (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE) {
2040-
RBASIC_SET_SHAPE_ID(RCLASS_ENSURE_FIELDS_OBJ(obj), shape_id);
2041+
// Avoid creating the fields_obj just to freeze the class
2042+
if (!(shape_id == SPECIAL_CONST_SHAPE_ID && old_shape_id == ROOT_SHAPE_ID)) {
2043+
RBASIC_SET_SHAPE_ID(RCLASS_ENSURE_FIELDS_OBJ(obj), shape_id);
2044+
}
20412045
}
20422046
// FIXME: How to do multi-shape?
20432047
RBASIC_SET_SHAPE_ID(obj, shape_id);

0 commit comments

Comments
 (0)