diff options
author | Jean Boussier <[email protected]> | 2025-05-08 18:20:35 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2025-05-09 10:22:51 +0200 |
commit | e4f97ce38725a22fb75c60d8114ce47af9c423a8 (patch) | |
tree | b63d6236bdd11cd993a15a08cb74b94dc79e0ac0 /shape.c | |
parent | f8b3fc520f2ec19bca8f30e022bd8765187da7ac (diff) |
Refactor `rb_shape_depth` to take an ID rather than a pointer.
As well as `rb_shape_edges_count` and `rb_shape_memsize`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13283
Diffstat (limited to 'shape.c')
-rw-r--r-- | shape.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -382,9 +382,10 @@ rb_shape_get_shape_id(VALUE obj) } size_t -rb_shape_depth(rb_shape_t *shape) +rb_shape_depth(shape_id_t shape_id) { size_t depth = 1; + rb_shape_t *shape = rb_shape_get_shape_by_id(shape_id); while (shape->parent_id != INVALID_SHAPE_ID) { depth++; @@ -1120,8 +1121,9 @@ rb_shape_too_complex_p(rb_shape_t *shape) } size_t -rb_shape_edges_count(rb_shape_t *shape) +rb_shape_edges_count(shape_id_t shape_id) { + rb_shape_t *shape = rb_shape_get_shape_by_id(shape_id); if (shape->edges) { if (SINGLE_CHILD_P(shape->edges)) { return 1; @@ -1134,8 +1136,10 @@ rb_shape_edges_count(rb_shape_t *shape) } size_t -rb_shape_memsize(rb_shape_t *shape) +rb_shape_memsize(shape_id_t shape_id) { + rb_shape_t *shape = rb_shape_get_shape_by_id(shape_id); + size_t memsize = sizeof(rb_shape_t); if (shape->edges && !SINGLE_CHILD_P(shape->edges)) { memsize += rb_id_table_memsize(shape->edges); @@ -1244,9 +1248,8 @@ rb_shape_edge_name(rb_shape_t *shape) static VALUE rb_shape_export_depth(VALUE self) { - rb_shape_t *shape; - shape = rb_shape_get_shape_by_id(NUM2INT(rb_struct_getmember(self, rb_intern("id")))); - return SIZET2NUM(rb_shape_depth(shape)); + shape_id_t shape_id = NUM2INT(rb_struct_getmember(self, rb_intern("id"))); + return SIZET2NUM(rb_shape_depth(shape_id)); } static VALUE |