diff options
author | Masaki Matsushita <glass.saga@gmail.com> | 2021-02-06 17:01:42 +0900 |
---|---|---|
committer | Masaki Matsushita <glass.saga@gmail.com> | 2021-02-06 17:23:16 +0900 |
commit | e1e61e256bd65ac3f293ba1513d1a934b9a3bff9 (patch) | |
tree | 2ea619457505569a0a2e74c19c692e286a38791a /array.c | |
parent | 94fb62e4a01975d61ad074f882068fdd7d6ed474 (diff) |
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.
Diffstat (limited to 'array.c')
-rw-r--r-- | array.c | 1 |
1 files changed, 1 insertions, 0 deletions
@@ -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) { |