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 (patch)
treec6481c2eac6a9a51896d71b6063a0218f8d49915
parent31d0a5815c43b219eca356d0cc7dfedfb0569eca (diff)
Refactor `rb_shape_transition_frozen` to return a `shape_id`.
Notes
Notes: Merged: https://github.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
diff --git a/object.c b/object.c
index 0263bbba95..9dda1d584d 100644
--- a/object.c
+++ b/object.c
@@ -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)) {
+ shape_id_t next_shape_id = rb_shape_transition_frozen(clone);
+ if (!rb_shape_obj_too_complex(clone) && rb_shape_id_too_complex_p(next_shape_id)) {
rb_evict_ivars_to_hash(clone);
}
else {
- rb_shape_set_shape(clone, next_shape);
+ rb_shape_set_shape_id(clone, next_shape_id);
}
}
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);
+ 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
// 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);
}
else {
- rb_shape_set_shape(clone, next_shape);
+ rb_shape_set_shape_id(clone, next_shape_id);
}
break;
}
diff --git a/shape.c b/shape.c
index 9191f4e51e..86ca09646e 100644
--- a/shape.c
+++ b/shape.c
@@ -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)
+shape_id_t
+rb_shape_transition_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;
+ shape_id_t shape_id = rb_shape_get_shape_id(obj);
+ 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()) {
- return RSHAPE(SPECIAL_CONST_SHAPE_ID);
+ if (rb_shape_frozen_shape_p(shape)) {
+ return shape_id;
}
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);
- return next_shape;
+ return rb_shape_id(next_shape);
}
static rb_shape_t *
diff --git a/shape.h b/shape.h
index cbf021a712..d6818c24e8 100644
--- a/shape.h
+++ b/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);
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);
+shape_id_t rb_shape_transition_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);
diff --git a/variable.c b/variable.c
index 5da2fa44c3..a115ab87b4 100644
--- a/variable.c
+++ b/variable.c
@@ -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);
+ shape_id_t next_shape_id = rb_shape_transition_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)) {
+ if (rb_shape_id_too_complex_p(next_shape_id) && !rb_shape_obj_too_complex(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)) {
rb_freeze_singleton_class(x);