Skip to content

Commit a970d35

Browse files
committed
Get rid of rb_shape_get_parent.
1 parent 5782561 commit a970d35

3 files changed

Lines changed: 14 additions & 22 deletions

File tree

shape.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,6 @@ RSHAPE(shape_id_t shape_id)
347347
return &GET_SHAPE_TREE()->shape_list[shape_id];
348348
}
349349

350-
rb_shape_t *
351-
rb_shape_get_parent(rb_shape_t *shape)
352-
{
353-
return RSHAPE(shape->parent_id);
354-
}
355-
356350
#if !SHAPE_IN_BASIC_FLAGS
357351
shape_id_t rb_generic_shape_id(VALUE obj);
358352
#endif
@@ -388,7 +382,7 @@ rb_shape_depth(shape_id_t shape_id)
388382

389383
while (shape->parent_id != INVALID_SHAPE_ID) {
390384
depth++;
391-
shape = rb_shape_get_parent(shape);
385+
shape = RSHAPE(shape->parent_id);
392386
}
393387

394388
return depth;
@@ -446,7 +440,7 @@ redblack_cache_ancestors(rb_shape_t *shape)
446440
if (!(shape->ancestor_index || shape->parent_id == INVALID_SHAPE_ID)) {
447441
redblack_node_t *parent_index;
448442

449-
parent_index = redblack_cache_ancestors(rb_shape_get_parent(shape));
443+
parent_index = redblack_cache_ancestors(RSHAPE(shape->parent_id));
450444

451445
if (shape->type == SHAPE_IVAR) {
452446
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)
612606
if (shape->type == SHAPE_IVAR && shape->edge_name == id) {
613607
*removed_shape = shape;
614608

615-
return rb_shape_get_parent(shape);
609+
return RSHAPE(shape->parent_id);
616610
}
617611
else {
618612
// This isn't the IV we want to remove, keep walking up.
619-
rb_shape_t *new_parent = remove_shape_recursive(rb_shape_get_parent(shape), id, removed_shape);
613+
rb_shape_t *new_parent = remove_shape_recursive(RSHAPE(shape->parent_id), id, removed_shape);
620614

621615
// We found a new parent. Create a child of the new parent that
622616
// has the same attributes as this shape.
@@ -765,7 +759,7 @@ rb_shape_object_id_shape(VALUE obj)
765759

766760
if (shape->flags & SHAPE_FL_HAS_OBJECT_ID) {
767761
while (shape->type != SHAPE_OBJ_ID) {
768-
shape = rb_shape_get_parent(shape);
762+
shape = RSHAPE(shape->parent_id);
769763
}
770764
return shape;
771765
}
@@ -886,7 +880,7 @@ rb_shape_get_iv_index_with_hint(shape_id_t shape_id, ID id, attr_index_t *value,
886880

887881
while (depth > 0 && shape->next_field_index > index_hint) {
888882
while (shape_hint->next_field_index > shape->next_field_index) {
889-
shape_hint = rb_shape_get_parent(shape_hint);
883+
shape_hint = RSHAPE(shape_hint->parent_id);
890884
}
891885

892886
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,
902896
return true;
903897
}
904898

905-
shape = rb_shape_get_parent(shape);
899+
shape = RSHAPE(shape->parent_id);
906900
depth--;
907901
}
908902

@@ -938,7 +932,7 @@ shape_get_iv_index(rb_shape_t *shape, ID id, attr_index_t *value)
938932
}
939933
}
940934

941-
shape = rb_shape_get_parent(shape);
935+
shape = RSHAPE(shape->parent_id);
942936
}
943937

944938
return false;
@@ -1009,7 +1003,7 @@ shape_traverse_from_new_root(rb_shape_t *initial_shape, rb_shape_t *dest_shape)
10091003
rb_shape_t *next_shape = initial_shape;
10101004

10111005
if (dest_shape->type != initial_shape->type) {
1012-
next_shape = shape_traverse_from_new_root(initial_shape, rb_shape_get_parent(dest_shape));
1006+
next_shape = shape_traverse_from_new_root(initial_shape, RSHAPE(dest_shape->parent_id));
10131007
if (!next_shape) {
10141008
return NULL;
10151009
}
@@ -1075,7 +1069,7 @@ rb_shape_rebuild_shape(rb_shape_t *initial_shape, rb_shape_t *dest_shape)
10751069
RUBY_ASSERT(initial_shape->type == SHAPE_T_OBJECT || initial_shape->type == SHAPE_ROOT);
10761070

10771071
if (dest_shape->type != initial_shape->type) {
1078-
midway_shape = rb_shape_rebuild_shape(initial_shape, rb_shape_get_parent(dest_shape));
1072+
midway_shape = rb_shape_rebuild_shape(initial_shape, RSHAPE(dest_shape->parent_id));
10791073
if (UNLIKELY(rb_shape_id(midway_shape) == ROOT_TOO_COMPLEX_SHAPE_ID)) {
10801074
return midway_shape;
10811075
}
@@ -1257,7 +1251,7 @@ rb_shape_parent(VALUE self)
12571251
rb_shape_t *shape;
12581252
shape = RSHAPE(NUM2INT(rb_struct_getmember(self, rb_intern("id"))));
12591253
if (shape->parent_id != INVALID_SHAPE_ID) {
1260-
return rb_shape_t_to_rb_cShape(rb_shape_get_parent(shape));
1254+
return rb_shape_t_to_rb_cShape(RSHAPE(shape->parent_id));
12611255
}
12621256
else {
12631257
return Qnil;

shape.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ RCLASS_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
151151

152152
int32_t rb_shape_id_offset(void);
153153

154-
rb_shape_t *rb_shape_get_parent(rb_shape_t *shape);
155-
156154
RUBY_FUNC_EXPORTED rb_shape_t *RSHAPE(shape_id_t shape_id);
157155
RUBY_FUNC_EXPORTED shape_id_t RB_OBJ_SHAPE_ID(VALUE obj);
158156
shape_id_t rb_shape_get_next_iv_shape(shape_id_t shape_id, ID id);

variable.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,12 +2143,12 @@ iterate_over_shapes_with_callback(rb_shape_t *shape, rb_ivar_foreach_callback_fu
21432143
return false;
21442144
case SHAPE_OBJ_ID:
21452145
if (itr_data->ivar_only) {
2146-
return iterate_over_shapes_with_callback(rb_shape_get_parent(shape), callback, itr_data);
2146+
return iterate_over_shapes_with_callback(RSHAPE(shape->parent_id), callback, itr_data);
21472147
}
21482148
// fallthrough
21492149
case SHAPE_IVAR:
21502150
ASSUME(callback);
2151-
if (iterate_over_shapes_with_callback(rb_shape_get_parent(shape), callback, itr_data)) {
2151+
if (iterate_over_shapes_with_callback(RSHAPE(shape->parent_id), callback, itr_data)) {
21522152
return true;
21532153
}
21542154

@@ -2180,7 +2180,7 @@ iterate_over_shapes_with_callback(rb_shape_t *shape, rb_ivar_foreach_callback_fu
21802180
}
21812181
return false;
21822182
case SHAPE_FROZEN:
2183-
return iterate_over_shapes_with_callback(rb_shape_get_parent(shape), callback, itr_data);
2183+
return iterate_over_shapes_with_callback(RSHAPE(shape->parent_id), callback, itr_data);
21842184
case SHAPE_OBJ_TOO_COMPLEX:
21852185
default:
21862186
rb_bug("Unreachable");

0 commit comments

Comments
 (0)