ruby-changes:49215
From: nobu <ko1@a...>
Date: Tue, 19 Dec 2017 10:08:59 +0900 (JST)
Subject: [ruby-changes:49215] nobu:r61330 (trunk): Improve Array#- efficiency [Fixes GH-1756]
nobu 2017-12-19 10:08:52 +0900 (Tue, 19 Dec 2017) New Revision: 61330 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61330 Log: Improve Array#- efficiency [Fixes GH-1756] 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?\195?\173a Mart?\195?\173nez G?\195?\179mez <ammartinez@s...> Modified files: trunk/array.c Index: array.c =================================================================== --- array.c (revision 61329) +++ array.c (revision 61330) @@ -4163,7 +4163,7 @@ rb_ary_diff(VALUE ary1, VALUE ary2) https://github.com/ruby/ruby/blob/trunk/array.c#L4163 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<RARRAY_LEN(ary1); i++) { VALUE elt = rb_ary_elt(ary1, i); if (rb_ary_includes_by_eql(ary2, elt)) continue; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/