From e1e61e256bd65ac3f293ba1513d1a934b9a3bff9 Mon Sep 17 00:00:00 2001 From: Masaki Matsushita Date: Sat, 6 Feb 2021 17:01:42 +0900 Subject: [PATCH] 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. --- array.c | 1 + 1 file changed, 1 insertion(+) diff --git a/array.c b/array.c index a73f4187b129eb..ad7e11afb708df 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) {