Skip to content

Commit

Permalink
Improve performance of Array#- when it is called with empty array
Browse files Browse the repository at this point in the history
This change make Array#- return a copy of the receiver when
the other array is empty.
  • Loading branch information
mmasaki committed Feb 6, 2021
1 parent 94fb62e commit e1e61e2
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -5291,6 +5291,7 @@ rb_ary_diff(VALUE ary1, VALUE ary2)
long i;

ary2 = to_ary(ary2);
if (RARRAY_LEN(ary2) == 0) { return ary_make_shared_copy(ary1); }
ary3 = rb_ary_new();

if (RARRAY_LEN(ary1) <= SMALL_ARRAY_LEN || RARRAY_LEN(ary2) <= SMALL_ARRAY_LEN) {
Expand Down

0 comments on commit e1e61e2

Please sign in to comment.