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:
parent
94fb62e4a0
commit
e1e61e256b
1 changed files with 1 additions and 0 deletions
1
array.c
1
array.c
|
@ -5291,6 +5291,7 @@ rb_ary_diff(VALUE ary1, VALUE ary2)
|
||||||
long i;
|
long i;
|
||||||
|
|
||||||
ary2 = to_ary(ary2);
|
ary2 = to_ary(ary2);
|
||||||
|
if (RARRAY_LEN(ary2) == 0) { return ary_make_shared_copy(ary1); }
|
||||||
ary3 = rb_ary_new();
|
ary3 = rb_ary_new();
|
||||||
|
|
||||||
if (RARRAY_LEN(ary1) <= SMALL_ARRAY_LEN || RARRAY_LEN(ary2) <= SMALL_ARRAY_LEN) {
|
if (RARRAY_LEN(ary1) <= SMALL_ARRAY_LEN || RARRAY_LEN(ary2) <= SMALL_ARRAY_LEN) {
|
||||||
|
|
Loading…
Reference in a new issue