diff --git a/internal/class.h b/internal/class.h index 0ac8e7c875..3e5108a3bd 100644 --- a/internal/class.h +++ b/internal/class.h @@ -62,9 +62,6 @@ struct rb_classext_struct { } singleton_class; } as; const VALUE includer; -#if !SHAPE_IN_BASIC_FLAGS - shape_id_t shape_id; -#endif attr_index_t max_iv_count; unsigned char variation_count; bool permanent_classpath : 1; diff --git a/shape.c b/shape.c index 05e5d76f60..5694833bfa 100644 --- a/shape.c +++ b/shape.c @@ -69,13 +69,6 @@ rb_shape_get_parent(rb_shape_t * shape) } #if !SHAPE_IN_BASIC_FLAGS -shape_id_t -rb_rclass_shape_id(VALUE obj) -{ - RUBY_ASSERT(RB_TYPE_P(obj, T_CLASS) || RB_TYPE_P(obj, T_MODULE)); - return RCLASS_EXT(obj)->shape_id; -} - shape_id_t rb_generic_shape_id(VALUE obj); #endif diff --git a/shape.h b/shape.h index dc4a3d5ce1..025dfb4dd8 100644 --- a/shape.h +++ b/shape.h @@ -77,16 +77,15 @@ rb_current_shape_tree(void) } #define GET_SHAPE_TREE() rb_current_shape_tree() -#if SHAPE_IN_BASIC_FLAGS static inline shape_id_t -RBASIC_SHAPE_ID(VALUE obj) +get_shape_id_from_flags(VALUE obj) { RUBY_ASSERT(!RB_SPECIAL_CONST_P(obj)); return (shape_id_t)(SHAPE_MASK & ((RBASIC(obj)->flags) >> SHAPE_FLAG_SHIFT)); } static inline void -RBASIC_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id) +set_shape_id_in_flags(VALUE obj, shape_id_t shape_id) { // Ractors are occupying the upper 32 bits of flags, but only in debug mode // Object shapes are occupying top bits @@ -94,52 +93,49 @@ RBASIC_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id) RBASIC(obj)->flags |= ((VALUE)(shape_id) << SHAPE_FLAG_SHIFT); } + +#if SHAPE_IN_BASIC_FLAGS +static inline shape_id_t +RBASIC_SHAPE_ID(VALUE obj) +{ + return get_shape_id_from_flags(obj); +} + +static inline void +RBASIC_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id) +{ + set_shape_id_in_flags(obj, shape_id); +} +#endif + static inline shape_id_t ROBJECT_SHAPE_ID(VALUE obj) { RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT); - return RBASIC_SHAPE_ID(obj); + return get_shape_id_from_flags(obj); } static inline void ROBJECT_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id) { RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT); - RBASIC_SET_SHAPE_ID(obj, shape_id); + set_shape_id_in_flags(obj, shape_id); } static inline shape_id_t RCLASS_SHAPE_ID(VALUE obj) { RUBY_ASSERT(RB_TYPE_P(obj, T_CLASS) || RB_TYPE_P(obj, T_MODULE)); - return RBASIC_SHAPE_ID(obj); -} - -#else - -static inline shape_id_t -ROBJECT_SHAPE_ID(VALUE obj) -{ - RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT); - return (shape_id_t)(SHAPE_MASK & (RBASIC(obj)->flags >> SHAPE_FLAG_SHIFT)); + return get_shape_id_from_flags(obj); } static inline void -ROBJECT_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id) +RCLASS_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id) { - RBASIC(obj)->flags &= SHAPE_FLAG_MASK; - RBASIC(obj)->flags |= ((VALUE)(shape_id) << SHAPE_FLAG_SHIFT); + RUBY_ASSERT(RB_TYPE_P(obj, T_CLASS) || RB_TYPE_P(obj, T_MODULE)); + set_shape_id_in_flags(obj, shape_id); } -shape_id_t rb_rclass_shape_id(VALUE obj); - -static inline shape_id_t RCLASS_SHAPE_ID(VALUE obj) -{ - return rb_rclass_shape_id(obj); -} - -#endif - rb_shape_t * rb_shape_get_root_shape(void); int32_t rb_shape_id_offset(void); diff --git a/variable.c b/variable.c index 90fa8760a0..39568db24a 100644 --- a/variable.c +++ b/variable.c @@ -1527,7 +1527,7 @@ rb_shape_set_shape_id(VALUE obj, shape_id_t shape_id) break; case T_CLASS: case T_MODULE: - RCLASS_EXT(obj)->shape_id = shape_id; + RCLASS_SET_SHAPE_ID(obj, shape_id); break; default: if (shape_id != SPECIAL_CONST_SHAPE_ID) {