summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2025-05-08 19:05:03 +0200
committerJean Boussier <[email protected]>2025-05-09 10:22:51 +0200
commitf82523f14bf69f73a4660611a16a67a88a408eda ()
treec6481c2eac6a9a51896d71b6063a0218f8d49915
parent31d0a5815c43b219eca356d0cc7dfedfb0569eca (diff)
Refactor `rb_shape_transition_frozen` to return a `shape_id`.
Notes: Merged: https://.com/ruby/ruby/pull/13283
-rw-r--r--object.c12
-rw-r--r--shape.c22
-rw-r--r--shape.h2
-rw-r--r--variable.c6
4 files changed, 21 insertions, 21 deletions
@@ -519,12 +519,12 @@ rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze)
}
if (RB_OBJ_FROZEN(obj)) {
- rb_shape_t *next_shape = rb_shape_transition_shape_frozen(clone);
- if (!rb_shape_obj_too_complex(clone) && rb_shape_too_complex_p(next_shape)) {
rb_evict_ivars_to_hash(clone);
}
else {
- rb_shape_set_shape(clone, next_shape);
}
}
break;
@@ -541,14 +541,14 @@ rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze)
argv[1] = freeze_true_hash;
rb_funcallv_kw(clone, id_init_clone, 2, argv, RB_PASS_KEYWORDS);
RBASIC(clone)->flags |= FL_FREEZE;
- rb_shape_t *next_shape = rb_shape_transition_shape_frozen(clone);
// If we're out of shapes, but we want to freeze, then we need to
// evacuate this clone to a hash
- if (!rb_shape_obj_too_complex(clone) && rb_shape_too_complex_p(next_shape)) {
rb_evict_ivars_to_hash(clone);
}
else {
- rb_shape_set_shape(clone, next_shape);
}
break;
}
@@ -700,28 +700,28 @@ rb_shape_transition_shape_remove_ivar(VALUE obj, ID id, rb_shape_t *shape, VALUE
return true;
}
-rb_shape_t *
-rb_shape_transition_shape_frozen(VALUE obj)
{
- rb_shape_t *shape = rb_shape_get_shape(obj);
- RUBY_ASSERT(shape);
RUBY_ASSERT(RB_OBJ_FROZEN(obj));
- if (rb_shape_frozen_shape_p(shape)) {
- return shape;
}
- rb_shape_t *next_shape;
- if (shape == rb_shape_get_root_shape()) {
- return RSHAPE(SPECIAL_CONST_SHAPE_ID);
}
bool dont_care;
- next_shape = get_next_shape_internal(shape, id_frozen, SHAPE_FROZEN, &dont_care, true);
RUBY_ASSERT(next_shape);
- return next_shape;
}
static rb_shape_t *
@@ -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);
rb_shape_t *rb_shape_get_shape(VALUE obj);
bool rb_shape_frozen_shape_p(rb_shape_t *shape);
-rb_shape_t *rb_shape_transition_shape_frozen(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);
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_shape_t * next_shape = rb_shape_transition_shape_frozen(x);
// If we're transitioning from "not complex" to "too complex"
// 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)) {
rb_evict_fields_to_hash(x);
}
- rb_shape_set_shape(x, next_shape);
if (RBASIC_CLASS(x)) {
rb_freeze_singleton_class(x);