From 3c653fc0d481a568aa8ff8f32c6c1dcc5fca418b Mon Sep 17 00:00:00 2001 From: dearblue Date: Fri, 18 Jul 2025 22:51:00 +0900 Subject: [PATCH] Share array entities if possible with `ary.replace(frozen_ary)` Currently mruby is limited to always placing array entities on the rewritable heap. Therefore, if the original array was frozen and only rewritable objects survived the subsequent process, the array entity can be changed. If an array object that actually shared the array entity is frozen with `ary.freeze`, there should be no problem, since the shared state is still kept. --- src/array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/array.c b/src/array.c index 28af8d5c4f..1d441169fc 100644 --- a/src/array.c +++ b/src/array.c @@ -511,7 +511,7 @@ ary_replace(mrb_state *mrb, struct RArray *a, struct RArray *b) mrb_write_barrier(mrb, (struct RBasic*)a); return; } - if (!mrb_frozen_p(b) && len > ARY_REPLACE_SHARED_MIN) { + if (len > ARY_REPLACE_SHARED_MIN) { ary_make_shared(mrb, b); goto shared_b; }