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

Improve performance of Array#- when it is called with empty array

This change make Array#- return a copy of the receiver when
the other array is empty.
This commit is contained in:
Masaki Matsushita 2021-02-06 17:01:42 +09:00
parent 94fb62e4a0
commit e1e61e256b

View file

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