Skip to content

Commit e535f82

Browse files
committed
Get rid of rb_shape_id(rb_shape_t *)
We should avoid conversions from `rb_shape_t *` into `shape_id_t` outside of `shape.c` as the short term goal is to have `shape_id_t` contain tags.
1 parent cc48fcd commit e535f82

File tree

7 files changed

+11
-15
lines changed

7 files changed

+11
-15
lines changed

ext/objspace/objspace_dump.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,15 +784,15 @@ objspace_dump(VALUE os, VALUE obj, VALUE output)
784784
}
785785

786786
static void
787-
shape_i(rb_shape_t *shape, void *data)
787+
shape_id_i(shape_id_t shape_id, void *data)
788788
{
789789
struct dump_config *dc = (struct dump_config *)data;
790790

791-
shape_id_t shape_id = rb_shape_id(shape);
792791
if (shape_id < dc->shapes_since) {
793792
return;
794793
}
795794

795+
rb_shape_t *shape = RSHAPE(shape_id);
796796
dump_append(dc, "{\"address\":");
797797
dump_append_ref(dc, (VALUE)shape);
798798

@@ -855,7 +855,7 @@ objspace_dump_all(VALUE os, VALUE output, VALUE full, VALUE since, VALUE shapes)
855855
}
856856

857857
if (RTEST(shapes)) {
858-
rb_shape_each_shape(shape_i, &dc);
858+
rb_shape_each_shape_id(shape_id_i, &dc);
859859
}
860860

861861
/* dump all objects */
@@ -872,7 +872,7 @@ objspace_dump_shapes(VALUE os, VALUE output, VALUE shapes)
872872
dump_output(&dc, output, Qfalse, Qnil, shapes);
873873

874874
if (RTEST(shapes)) {
875-
rb_shape_each_shape(shape_i, &dc);
875+
rb_shape_each_shape_id(shape_id_i, &dc);
876876
}
877877
return dump_result(&dc);
878878
}

shape.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ rb_shape_get_root_shape(void)
319319
return GET_SHAPE_TREE()->root_shape;
320320
}
321321

322-
shape_id_t
322+
static inline shape_id_t
323323
rb_shape_id(rb_shape_t *shape)
324324
{
325325
if (shape == NULL) {
@@ -329,12 +329,13 @@ rb_shape_id(rb_shape_t *shape)
329329
}
330330

331331
void
332-
rb_shape_each_shape(each_shape_callback callback, void *data)
332+
rb_shape_each_shape_id(each_shape_callback callback, void *data)
333333
{
334-
rb_shape_t *cursor = rb_shape_get_root_shape();
334+
rb_shape_t *start = rb_shape_get_root_shape();
335+
rb_shape_t *cursor = start;
335336
rb_shape_t *end = RSHAPE(GET_SHAPE_TREE()->next_shape_id);
336337
while (cursor < end) {
337-
callback(cursor, data);
338+
callback((shape_id_t)(cursor - start), data);
338339
cursor += 1;
339340
}
340341
}

shape.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,11 @@ rb_shape_obj_has_id(VALUE obj)
219219

220220
// For ext/objspace
221221
RUBY_SYMBOL_EXPORT_BEGIN
222-
typedef void each_shape_callback(rb_shape_t *shape, void *data);
223-
void rb_shape_each_shape(each_shape_callback callback, void *data);
222+
typedef void each_shape_callback(shape_id_t shape_id, void *data);
223+
void rb_shape_each_shape_id(each_shape_callback callback, void *data);
224224
size_t rb_shape_memsize(shape_id_t shape);
225225
size_t rb_shape_edges_count(shape_id_t shape_id);
226226
size_t rb_shape_depth(shape_id_t shape_id);
227-
shape_id_t rb_shape_id(rb_shape_t *shape);
228227
RUBY_SYMBOL_EXPORT_END
229228

230229
#endif

yjit/bindgen/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ fn main() {
9999
.allowlist_function("rb_shape_id_offset")
100100
.allowlist_function("rb_shape_get_iv_index")
101101
.allowlist_function("rb_shape_transition_add_ivar_no_warnings")
102-
.allowlist_function("rb_shape_id")
103102
.allowlist_function("rb_shape_obj_too_complex_p")
104103
.allowlist_function("rb_shape_too_complex_p")
105104
.allowlist_var("SHAPE_ID_NUM_BITS")

yjit/src/cruby_bindings.inc.rs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zjit/bindgen/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ fn main() {
112112
.allowlist_function("rb_shape_id_offset")
113113
.allowlist_function("rb_shape_get_iv_index")
114114
.allowlist_function("rb_shape_transition_add_ivar_no_warnings")
115-
.allowlist_function("rb_shape_id")
116115
.allowlist_function("rb_shape_obj_too_complex_p")
117116
.allowlist_var("SHAPE_ID_NUM_BITS")
118117

zjit/src/cruby_bindings.inc.rs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)