summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorMasaki Matsushita <glass.saga@gmail.com>2021-02-06 17:01:42 +0900
committerMasaki Matsushita <glass.saga@gmail.com>2021-02-06 17:23:16 +0900
commite1e61e256bd65ac3f293ba1513d1a934b9a3bff9 (patch)
tree2ea619457505569a0a2e74c19c692e286a38791a /array.c
parent94fb62e4a01975d61ad074f882068fdd7d6ed474 (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.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/array.c b/array.c
index a73f4187b1..ad7e11afb7 100644
--- a/array.c
+++ b/array.c
@@ -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) {