[前][次][番号順一覧][スレッド一覧]

ruby-changes:71340

From: Peter <ko1@a...>
Date: Mon, 7 Mar 2022 23:38:27 +0900 (JST)
Subject: [ruby-changes:71340] c445963575 (master): Use rb_ary_unshare for shared array in rb_ary_replace

https://git.ruby-lang.org/ruby.git/commit/?id=c445963575

From c445963575a8572f6b0baf7135093c128adab3b9 Mon Sep 17 00:00:00 2001
From: Peter Zhu <peter@p...>
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) https://github.com/ruby/ruby/blob/trunk/array.c#L4392
     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.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]