1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Use rb_ary_unshare for shared array in rb_ary_replace

rb_ary_unshare will perform FL_UNSET_SHARED and
rb_ary_decrement_share.
This commit is contained in:
Peter Zhu 2022-03-07 09:35:24 -05:00
parent 9cbebdcb74
commit c445963575

View file

@ -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 {