Skip to content

Commit 3135edd

Browse files
committed
Refactor FIRST_T_OBJECT_SHAPE_ID to not be used outside shape.c
1 parent e2f5e23 commit 3135edd

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ rb_gc_rebuild_shape(VALUE obj, size_t heap_id)
384384
return (uint32_t)orig_shape_id;
385385
}
386386

387-
shape_id_t initial_shape_id = (shape_id_t)(heap_id + FIRST_T_OBJECT_SHAPE_ID);
387+
shape_id_t initial_shape_id = rb_shape_root(heap_id);
388388
shape_id_t new_shape_id = rb_shape_traverse_from_new_root(initial_shape_id, orig_shape_id);
389389

390390
if (new_shape_id == INVALID_SHAPE_ID) {

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ rb_class_allocate_instance(VALUE klass)
135135
RUBY_ASSERT(rb_obj_shape(obj)->type == SHAPE_ROOT);
136136

137137
// Set the shape to the specific T_OBJECT shape.
138-
ROBJECT_SET_SHAPE_ID(obj, (shape_id_t)(rb_gc_heap_id_for_size(size) + FIRST_T_OBJECT_SHAPE_ID));
138+
ROBJECT_SET_SHAPE_ID(obj, rb_shape_root(rb_gc_heap_id_for_size(size)));
139139

140140
#if RUBY_DEBUG
141141
RUBY_ASSERT(!rb_shape_obj_too_complex_p(obj));

shape.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ Init_default_shapes(void)
14191419
t_object_shape->capacity = (uint32_t)((sizes[i] - offsetof(struct RObject, as.ary)) / sizeof(VALUE));
14201420
t_object_shape->edges = rb_id_table_create(0);
14211421
t_object_shape->ancestor_index = LEAF;
1422-
RUBY_ASSERT(rb_shape_id(t_object_shape) == (shape_id_t)(i + FIRST_T_OBJECT_SHAPE_ID));
1422+
RUBY_ASSERT(rb_shape_id(t_object_shape) == rb_shape_root(i));
14231423
}
14241424

14251425
// Prebuild TOO_COMPLEX variations so that they already exist if we ever need them after we

shape.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ rb_shape_canonical_p(rb_shape_t *shape)
187187
return !shape->flags;
188188
}
189189

190+
static inline shape_id_t
191+
rb_shape_root(size_t heap_id)
192+
{
193+
return (shape_id_t)(heap_id + FIRST_T_OBJECT_SHAPE_ID);
194+
}
195+
190196
static inline uint32_t
191197
ROBJECT_FIELDS_CAPACITY(VALUE obj)
192198
{

0 commit comments

Comments
 (0)