ruby-changes:65157
From: Masaki <ko1@a...>
Date: Sat, 6 Feb 2021 17:24:52 +0900 (JST)
Subject: [ruby-changes:65157] e1e61e256b (master): Improve performance of Array#- when it is called with empty array
https://git.ruby-lang.org/ruby.git/commit/?id=e1e61e256b From e1e61e256bd65ac3f293ba1513d1a934b9a3bff9 Mon Sep 17 00:00:00 2001 From: Masaki Matsushita <glass.saga@g...> Date: Sat, 6 Feb 2021 17:01:42 +0900 Subject: 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 a73f418..ad7e11a 100644 --- a/array.c +++ b/array.c @@ -5291,6 +5291,7 @@ rb_ary_diff(VALUE ary1, VALUE ary2) https://github.com/ruby/ruby/blob/trunk/array.c#L5291 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) { -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/