From 627452e3406e0db2583c8ecc46b46ee54aea1aad Mon Sep 17 00:00:00 2001 From: dearblue Date: Fri, 18 Jul 2025 23:01:28 +0900 Subject: [PATCH] Sharing arrays with `ary_dup()` Until now, the array entity has always been allocated from the heap and copied. However, this allows the array entity to be shared with the source if possible. --- src/array.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/array.c b/src/array.c index 28af8d5c4..bca64c400 100644 --- a/src/array.c +++ b/src/array.c @@ -934,7 +934,9 @@ mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val) static struct RArray* ary_dup(mrb_state *mrb, struct RArray *a) { - return ary_new_from_values(mrb, ARY_LEN(a), ARY_PTR(a)); + struct RArray *dup = ary_new_capa(mrb, 0); + ary_replace(mrb, dup, a); + return dup; } MRB_API mrb_value