Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,28 @@ rb_ary_frozen_p(VALUE ary)
modified from the snapshot. The snapshot is cheap, though if
something does modify the array it will pay the cost of copying
it. */
VALUE
rb_ary_dup_of_p(VALUE ary1, VALUE ary2)
{
VALUE *p1, *p2;
long len = RARRAY_LEN(ary1);

if (len != RARRAY_LEN(ary2)) return Qfalse;

p1 = RARRAY_PTR(ary1);
p2 = RARRAY_PTR(ary2);

if (ARY_EMBED_P(ary1) && ARY_EMBED_P(ary2)) {
for (; len; len--, p1++, p2++) {
if (*p1 != *p2) return Qfalse;
}
return Qtrue;
}

if (p1 == p2) return Qtrue;
return Qfalse;
}

VALUE
rb_ary_shared_with_p(VALUE ary1, VALUE ary2)
{
Expand Down
1 change: 1 addition & 0 deletions include/ruby/intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ VALUE rb_ary_tmp_new(long);
void rb_ary_free(VALUE);
void rb_ary_modify(VALUE);
VALUE rb_ary_freeze(VALUE);
VALUE rb_ary_dup_of_p(VALUE, VALUE);
VALUE rb_ary_shared_with_p(VALUE, VALUE);
VALUE rb_ary_aref(int, VALUE*, VALUE);
VALUE rb_ary_subseq(VALUE, long, long);
Expand Down
4 changes: 2 additions & 2 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ rb_get_expanded_load_path(void)
rb_vm_t *vm = GET_VM();
const VALUE non_cache = Qtrue;

if (!rb_ary_shared_with_p(vm->load_path_snapshot, vm->load_path)) {
if (!rb_ary_dup_of_p(vm->load_path_snapshot, vm->load_path)) {
/* The load path was modified. Rebuild the expanded load path. */
int has_relative = 0, has_non_cache = 0;
rb_construct_expanded_load_path(EXPAND_ALL, &has_relative, &has_non_cache);
Expand Down Expand Up @@ -247,7 +247,7 @@ get_loaded_features_index(void)
int i;
rb_vm_t *vm = GET_VM();

if (!rb_ary_shared_with_p(vm->loaded_features_snapshot, vm->loaded_features)) {
if (!rb_ary_dup_of_p(vm->loaded_features_snapshot, vm->loaded_features)) {
/* The sharing was broken; something (other than us in rb_provide_feature())
modified loaded_features. Rebuild the index. */
rb_hash_clear(vm->loaded_features_index);
Expand Down