From 0d09ee1e73d0cf0daed28acd75deeb12f09f42b6 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 19 Dec 2017 01:08:52 +0000 Subject: Improve Array#- efficiency [Fixes GH-1756] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When doing the difference of a small array with a big one it is not efficient in both time and memory to convert the second one to a hash. From: Ana María Martínez Gómez git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'array.c') diff --git a/array.c b/array.c index b533e81055..e7f96f7685 100644 --- a/array.c +++ b/array.c @@ -4163,7 +4163,7 @@ rb_ary_diff(VALUE ary1, VALUE ary2) ary2 = to_ary(ary2); ary3 = rb_ary_new(); - if (RARRAY_LEN(ary2) <= SMALL_ARRAY_LEN) { + if (RARRAY_LEN(ary1) <= SMALL_ARRAY_LEN || RARRAY_LEN(ary2) <= SMALL_ARRAY_LEN) { for (i=0; i