Skip to content

Commit

Permalink
Use rb_ary_unshare for shared array in rb_ary_replace
Browse files Browse the repository at this point in the history
rb_ary_unshare will perform FL_UNSET_SHARED and
rb_ary_decrement_share.
  • Loading branch information
peterzhu2118 committed Mar 7, 2022
1 parent 9cbebdc commit c445963
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions array.c
Expand Up @@ -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 {
Expand Down

0 comments on commit c445963

Please sign in to comment.