From c445963575a8572f6b0baf7135093c128adab3b9 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 7 Mar 2022 09:35:24 -0500 Subject: Use rb_ary_unshare for shared array in rb_ary_replace rb_ary_unshare will perform FL_UNSET_SHARED and rb_ary_decrement_share. --- array.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/array.c b/array.c index 11ae67ead3..448bcd365e 100644 --- a/array.c +++ b/array.c @@ -4392,20 +4392,14 @@ rb_ary_replace(VALUE copy, VALUE orig) if (copy == orig) return copy; if (RARRAY_LEN(orig) <= RARRAY_EMBED_LEN_MAX) { - VALUE shared_root = 0; - if (ARY_OWNS_HEAP_P(copy)) { ary_heap_free(copy); } else if (ARY_SHARED_P(copy)) { - shared_root = ARY_SHARED_ROOT(copy); - FL_UNSET_SHARED(copy); + rb_ary_unshare(copy); } FL_SET_EMBED(copy); ary_memcpy(copy, 0, RARRAY_LEN(orig), RARRAY_CONST_PTR_TRANSIENT(orig)); - if (shared_root) { - rb_ary_decrement_share(shared_root); - } ARY_SET_LEN(copy, RARRAY_LEN(orig)); } else { -- cgit v1.2.3