summaryrefslogtreecommitdiff
path: root/shape.c
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2023-11-21 17:23:56 +0100
committerJean Boussier <jean.boussier@gmail.com>2023-11-22 10:12:07 +0100
commit2d7fb9c2fa5ab6c967f8ff1bc350ce5d3d5344a2 (patch)
treea6ec5d70e9863d12b040d33cb0061631968e272a /shape.c
parent0745c0c5efdd38d88970dcadad780da61f64655a (diff)
Speedup test_shape.rb
Many tests start by exhausting all shapes, which is a slow process. By exposing a method to directly move the bump allocator forward we cut test runtime in half. Before: ``` Finished tests in 1.544756s ``` After: ``` Finished tests in 0.759733s, ```
Diffstat (limited to 'shape.c')
-rw-r--r--shape.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/shape.c b/shape.c
index 5a4a271b30..de57551fcf 100644
--- a/shape.c
+++ b/shape.c
@@ -1057,6 +1057,15 @@ rb_shape_shapes_available(VALUE self)
return INT2NUM(MAX_SHAPE_ID - (GET_SHAPE_TREE()->next_shape_id - 1));
}
+static VALUE
+rb_shape_exhaust(int argc, VALUE *argv, VALUE self)
+{
+ rb_check_arity(argc, 0, 1);
+ int offset = argc == 1 ? NUM2INT(argv[0]) : 0;
+ GET_SHAPE_TREE()->next_shape_id = MAX_SHAPE_ID - offset;
+ return Qnil;
+}
+
VALUE rb_obj_shape(rb_shape_t* shape);
static enum rb_id_table_iterator_result collect_keys_and_values(ID key, VALUE value, void *ref)
@@ -1239,5 +1248,6 @@ Init_shape(void)
rb_define_singleton_method(rb_cShape, "of", rb_shape_debug_shape, 1);
rb_define_singleton_method(rb_cShape, "root_shape", rb_shape_root_shape, 0);
rb_define_singleton_method(rb_cShape, "shapes_available", rb_shape_shapes_available, 0);
+ rb_define_singleton_method(rb_cShape, "exhaust_shapes", rb_shape_exhaust, -1);
#endif
}