Get rid of rb_shape_get_parent.

This commit is contained in:
Jean Boussier 2025-05-08 21:08:40 +02:00
parent 5782561fc1
commit a970d35de2
Notes: git 2025-05-09 08:23:06 +00:00
3 changed files with 14 additions and 22 deletions

28
shape.c
View File

@ -347,12 +347,6 @@ RSHAPE(shape_id_t shape_id)
return &GET_SHAPE_TREE()->shape_list[shape_id]; return &GET_SHAPE_TREE()->shape_list[shape_id];
} }
rb_shape_t *
rb_shape_get_parent(rb_shape_t *shape)
{
return RSHAPE(shape->parent_id);
}
#if !SHAPE_IN_BASIC_FLAGS #if !SHAPE_IN_BASIC_FLAGS
shape_id_t rb_generic_shape_id(VALUE obj); shape_id_t rb_generic_shape_id(VALUE obj);
#endif #endif
@ -388,7 +382,7 @@ rb_shape_depth(shape_id_t shape_id)
while (shape->parent_id != INVALID_SHAPE_ID) { while (shape->parent_id != INVALID_SHAPE_ID) {
depth++; depth++;
shape = rb_shape_get_parent(shape); shape = RSHAPE(shape->parent_id);
} }
return depth; return depth;
@ -446,7 +440,7 @@ redblack_cache_ancestors(rb_shape_t *shape)
if (!(shape->ancestor_index || shape->parent_id == INVALID_SHAPE_ID)) { if (!(shape->ancestor_index || shape->parent_id == INVALID_SHAPE_ID)) {
redblack_node_t *parent_index; redblack_node_t *parent_index;
parent_index = redblack_cache_ancestors(rb_shape_get_parent(shape)); parent_index = redblack_cache_ancestors(RSHAPE(shape->parent_id));
if (shape->type == SHAPE_IVAR) { if (shape->type == SHAPE_IVAR) {
shape->ancestor_index = redblack_insert(parent_index, shape->edge_name, shape); shape->ancestor_index = redblack_insert(parent_index, shape->edge_name, shape);
@ -612,11 +606,11 @@ remove_shape_recursive(rb_shape_t *shape, ID id, rb_shape_t **removed_shape)
if (shape->type == SHAPE_IVAR && shape->edge_name == id) { if (shape->type == SHAPE_IVAR && shape->edge_name == id) {
*removed_shape = shape; *removed_shape = shape;
return rb_shape_get_parent(shape); return RSHAPE(shape->parent_id);
} }
else { else {
// This isn't the IV we want to remove, keep walking up. // This isn't the IV we want to remove, keep walking up.
rb_shape_t *new_parent = remove_shape_recursive(rb_shape_get_parent(shape), id, removed_shape); rb_shape_t *new_parent = remove_shape_recursive(RSHAPE(shape->parent_id), id, removed_shape);
// We found a new parent. Create a child of the new parent that // We found a new parent. Create a child of the new parent that
// has the same attributes as this shape. // has the same attributes as this shape.
@ -765,7 +759,7 @@ rb_shape_object_id_shape(VALUE obj)
if (shape->flags & SHAPE_FL_HAS_OBJECT_ID) { if (shape->flags & SHAPE_FL_HAS_OBJECT_ID) {
while (shape->type != SHAPE_OBJ_ID) { while (shape->type != SHAPE_OBJ_ID) {
shape = rb_shape_get_parent(shape); shape = RSHAPE(shape->parent_id);
} }
return shape; return shape;
} }
@ -886,7 +880,7 @@ rb_shape_get_iv_index_with_hint(shape_id_t shape_id, ID id, attr_index_t *value,
while (depth > 0 && shape->next_field_index > index_hint) { while (depth > 0 && shape->next_field_index > index_hint) {
while (shape_hint->next_field_index > shape->next_field_index) { while (shape_hint->next_field_index > shape->next_field_index) {
shape_hint = rb_shape_get_parent(shape_hint); shape_hint = RSHAPE(shape_hint->parent_id);
} }
if (shape_hint == shape) { if (shape_hint == shape) {
@ -902,7 +896,7 @@ rb_shape_get_iv_index_with_hint(shape_id_t shape_id, ID id, attr_index_t *value,
return true; return true;
} }
shape = rb_shape_get_parent(shape); shape = RSHAPE(shape->parent_id);
depth--; depth--;
} }
@ -938,7 +932,7 @@ shape_get_iv_index(rb_shape_t *shape, ID id, attr_index_t *value)
} }
} }
shape = rb_shape_get_parent(shape); shape = RSHAPE(shape->parent_id);
} }
return false; return false;
@ -1009,7 +1003,7 @@ shape_traverse_from_new_root(rb_shape_t *initial_shape, rb_shape_t *dest_shape)
rb_shape_t *next_shape = initial_shape; rb_shape_t *next_shape = initial_shape;
if (dest_shape->type != initial_shape->type) { if (dest_shape->type != initial_shape->type) {
next_shape = shape_traverse_from_new_root(initial_shape, rb_shape_get_parent(dest_shape)); next_shape = shape_traverse_from_new_root(initial_shape, RSHAPE(dest_shape->parent_id));
if (!next_shape) { if (!next_shape) {
return NULL; return NULL;
} }
@ -1075,7 +1069,7 @@ rb_shape_rebuild_shape(rb_shape_t *initial_shape, rb_shape_t *dest_shape)
RUBY_ASSERT(initial_shape->type == SHAPE_T_OBJECT || initial_shape->type == SHAPE_ROOT); RUBY_ASSERT(initial_shape->type == SHAPE_T_OBJECT || initial_shape->type == SHAPE_ROOT);
if (dest_shape->type != initial_shape->type) { if (dest_shape->type != initial_shape->type) {
midway_shape = rb_shape_rebuild_shape(initial_shape, rb_shape_get_parent(dest_shape)); midway_shape = rb_shape_rebuild_shape(initial_shape, RSHAPE(dest_shape->parent_id));
if (UNLIKELY(rb_shape_id(midway_shape) == ROOT_TOO_COMPLEX_SHAPE_ID)) { if (UNLIKELY(rb_shape_id(midway_shape) == ROOT_TOO_COMPLEX_SHAPE_ID)) {
return midway_shape; return midway_shape;
} }
@ -1257,7 +1251,7 @@ rb_shape_parent(VALUE self)
rb_shape_t *shape; rb_shape_t *shape;
shape = RSHAPE(NUM2INT(rb_struct_getmember(self, rb_intern("id")))); shape = RSHAPE(NUM2INT(rb_struct_getmember(self, rb_intern("id"))));
if (shape->parent_id != INVALID_SHAPE_ID) { if (shape->parent_id != INVALID_SHAPE_ID) {
return rb_shape_t_to_rb_cShape(rb_shape_get_parent(shape)); return rb_shape_t_to_rb_cShape(RSHAPE(shape->parent_id));
} }
else { else {
return Qnil; return Qnil;

View File

@ -151,8 +151,6 @@ RCLASS_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
int32_t rb_shape_id_offset(void); int32_t rb_shape_id_offset(void);
rb_shape_t *rb_shape_get_parent(rb_shape_t *shape);
RUBY_FUNC_EXPORTED rb_shape_t *RSHAPE(shape_id_t shape_id); RUBY_FUNC_EXPORTED rb_shape_t *RSHAPE(shape_id_t shape_id);
RUBY_FUNC_EXPORTED shape_id_t RB_OBJ_SHAPE_ID(VALUE obj); RUBY_FUNC_EXPORTED shape_id_t RB_OBJ_SHAPE_ID(VALUE obj);
shape_id_t rb_shape_get_next_iv_shape(shape_id_t shape_id, ID id); shape_id_t rb_shape_get_next_iv_shape(shape_id_t shape_id, ID id);

View File

@ -2143,12 +2143,12 @@ iterate_over_shapes_with_callback(rb_shape_t *shape, rb_ivar_foreach_callback_fu
return false; return false;
case SHAPE_OBJ_ID: case SHAPE_OBJ_ID:
if (itr_data->ivar_only) { if (itr_data->ivar_only) {
return iterate_over_shapes_with_callback(rb_shape_get_parent(shape), callback, itr_data); return iterate_over_shapes_with_callback(RSHAPE(shape->parent_id), callback, itr_data);
} }
// fallthrough // fallthrough
case SHAPE_IVAR: case SHAPE_IVAR:
ASSUME(callback); ASSUME(callback);
if (iterate_over_shapes_with_callback(rb_shape_get_parent(shape), callback, itr_data)) { if (iterate_over_shapes_with_callback(RSHAPE(shape->parent_id), callback, itr_data)) {
return true; return true;
} }
@ -2180,7 +2180,7 @@ iterate_over_shapes_with_callback(rb_shape_t *shape, rb_ivar_foreach_callback_fu
} }
return false; return false;
case SHAPE_FROZEN: case SHAPE_FROZEN:
return iterate_over_shapes_with_callback(rb_shape_get_parent(shape), callback, itr_data); return iterate_over_shapes_with_callback(RSHAPE(shape->parent_id), callback, itr_data);
case SHAPE_OBJ_TOO_COMPLEX: case SHAPE_OBJ_TOO_COMPLEX:
default: default:
rb_bug("Unreachable"); rb_bug("Unreachable");