Refactor rb_shape_transition_frozen
to return a shape_id
.
This commit is contained in:
parent
31d0a5815c
commit
f82523f14b
Notes:
git
2025-05-09 08:23:10 +00:00
12
object.c
12
object.c
@ -519,12 +519,12 @@ rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (RB_OBJ_FROZEN(obj)) {
|
if (RB_OBJ_FROZEN(obj)) {
|
||||||
rb_shape_t *next_shape = rb_shape_transition_shape_frozen(clone);
|
shape_id_t next_shape_id = rb_shape_transition_frozen(clone);
|
||||||
if (!rb_shape_obj_too_complex(clone) && rb_shape_too_complex_p(next_shape)) {
|
if (!rb_shape_obj_too_complex(clone) && rb_shape_id_too_complex_p(next_shape_id)) {
|
||||||
rb_evict_ivars_to_hash(clone);
|
rb_evict_ivars_to_hash(clone);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_shape_set_shape(clone, next_shape);
|
rb_shape_set_shape_id(clone, next_shape_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -541,14 +541,14 @@ rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze)
|
|||||||
argv[1] = freeze_true_hash;
|
argv[1] = freeze_true_hash;
|
||||||
rb_funcallv_kw(clone, id_init_clone, 2, argv, RB_PASS_KEYWORDS);
|
rb_funcallv_kw(clone, id_init_clone, 2, argv, RB_PASS_KEYWORDS);
|
||||||
RBASIC(clone)->flags |= FL_FREEZE;
|
RBASIC(clone)->flags |= FL_FREEZE;
|
||||||
rb_shape_t *next_shape = rb_shape_transition_shape_frozen(clone);
|
shape_id_t next_shape_id = rb_shape_transition_frozen(clone);
|
||||||
// If we're out of shapes, but we want to freeze, then we need to
|
// If we're out of shapes, but we want to freeze, then we need to
|
||||||
// evacuate this clone to a hash
|
// evacuate this clone to a hash
|
||||||
if (!rb_shape_obj_too_complex(clone) && rb_shape_too_complex_p(next_shape)) {
|
if (!rb_shape_obj_too_complex(clone) && rb_shape_id_too_complex_p(next_shape_id)) {
|
||||||
rb_evict_ivars_to_hash(clone);
|
rb_evict_ivars_to_hash(clone);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_shape_set_shape(clone, next_shape);
|
rb_shape_set_shape_id(clone, next_shape_id);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
22
shape.c
22
shape.c
@ -700,28 +700,28 @@ rb_shape_transition_shape_remove_ivar(VALUE obj, ID id, rb_shape_t *shape, VALUE
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_shape_t *
|
shape_id_t
|
||||||
rb_shape_transition_shape_frozen(VALUE obj)
|
rb_shape_transition_frozen(VALUE obj)
|
||||||
{
|
{
|
||||||
rb_shape_t *shape = rb_shape_get_shape(obj);
|
|
||||||
RUBY_ASSERT(shape);
|
|
||||||
RUBY_ASSERT(RB_OBJ_FROZEN(obj));
|
RUBY_ASSERT(RB_OBJ_FROZEN(obj));
|
||||||
|
|
||||||
if (rb_shape_frozen_shape_p(shape)) {
|
shape_id_t shape_id = rb_shape_get_shape_id(obj);
|
||||||
return shape;
|
if (shape_id == ROOT_SHAPE_ID) {
|
||||||
|
return SPECIAL_CONST_SHAPE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_shape_t *next_shape;
|
rb_shape_t *shape = RSHAPE(shape_id);
|
||||||
|
RUBY_ASSERT(shape);
|
||||||
|
|
||||||
if (shape == rb_shape_get_root_shape()) {
|
if (rb_shape_frozen_shape_p(shape)) {
|
||||||
return RSHAPE(SPECIAL_CONST_SHAPE_ID);
|
return shape_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool dont_care;
|
bool dont_care;
|
||||||
next_shape = get_next_shape_internal(shape, id_frozen, SHAPE_FROZEN, &dont_care, true);
|
rb_shape_t *next_shape = get_next_shape_internal(shape, id_frozen, SHAPE_FROZEN, &dont_care, true);
|
||||||
|
|
||||||
RUBY_ASSERT(next_shape);
|
RUBY_ASSERT(next_shape);
|
||||||
return next_shape;
|
return rb_shape_id(next_shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
static rb_shape_t *
|
static rb_shape_t *
|
||||||
|
2
shape.h
2
shape.h
@ -165,7 +165,7 @@ bool rb_shape_id_too_complex_p(shape_id_t shape_id);
|
|||||||
void rb_shape_set_shape(VALUE obj, rb_shape_t *shape);
|
void rb_shape_set_shape(VALUE obj, rb_shape_t *shape);
|
||||||
rb_shape_t *rb_shape_get_shape(VALUE obj);
|
rb_shape_t *rb_shape_get_shape(VALUE obj);
|
||||||
bool rb_shape_frozen_shape_p(rb_shape_t *shape);
|
bool rb_shape_frozen_shape_p(rb_shape_t *shape);
|
||||||
rb_shape_t *rb_shape_transition_shape_frozen(VALUE obj);
|
shape_id_t rb_shape_transition_frozen(VALUE obj);
|
||||||
rb_shape_t *rb_shape_transition_shape_too_complex(VALUE obj);
|
rb_shape_t *rb_shape_transition_shape_too_complex(VALUE obj);
|
||||||
bool rb_shape_transition_shape_remove_ivar(VALUE obj, ID id, rb_shape_t *shape, VALUE *removed);
|
bool rb_shape_transition_shape_remove_ivar(VALUE obj, ID id, rb_shape_t *shape, VALUE *removed);
|
||||||
rb_shape_t *rb_shape_get_next(rb_shape_t *shape, VALUE obj, ID id);
|
rb_shape_t *rb_shape_get_next(rb_shape_t *shape, VALUE obj, ID id);
|
||||||
|
@ -2010,14 +2010,14 @@ void rb_obj_freeze_inline(VALUE x)
|
|||||||
RB_FL_UNSET_RAW(x, FL_USER2 | FL_USER3); // STR_CHILLED
|
RB_FL_UNSET_RAW(x, FL_USER2 | FL_USER3); // STR_CHILLED
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_shape_t * next_shape = rb_shape_transition_shape_frozen(x);
|
shape_id_t next_shape_id = rb_shape_transition_frozen(x);
|
||||||
|
|
||||||
// If we're transitioning from "not complex" to "too complex"
|
// If we're transitioning from "not complex" to "too complex"
|
||||||
// then evict ivars. This can happen if we run out of shapes
|
// then evict ivars. This can happen if we run out of shapes
|
||||||
if (rb_shape_too_complex_p(next_shape) && !rb_shape_obj_too_complex(x)) {
|
if (rb_shape_id_too_complex_p(next_shape_id) && !rb_shape_obj_too_complex(x)) {
|
||||||
rb_evict_fields_to_hash(x);
|
rb_evict_fields_to_hash(x);
|
||||||
}
|
}
|
||||||
rb_shape_set_shape(x, next_shape);
|
rb_shape_set_shape_id(x, next_shape_id);
|
||||||
|
|
||||||
if (RBASIC_CLASS(x)) {
|
if (RBASIC_CLASS(x)) {
|
||||||
rb_freeze_singleton_class(x);
|
rb_freeze_singleton_class(x);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user