From ffb1df52c1f8a8e1805e310448eb66665804b5fc Mon Sep 17 00:00:00 2001 From: lvl0nax Date: Mon, 25 Apr 2016 09:46:49 +0300 Subject: Little perfomance fix for Array#split. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calculating ------------------------------------- before 40.770k i/100ms after 58.464k i/100ms ------------------------------------------------- before 629.568k (± 5.0%) i/s - 3.180M after 1.159M (± 4.5%) i/s - 5.788M --- .../lib/active_support/core_ext/array/grouping.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/array/grouping.rb b/activesupport/lib/active_support/core_ext/array/grouping.rb index 87ae052eb0..34af83d1ab 100644 --- a/activesupport/lib/active_support/core_ext/array/grouping.rb +++ b/activesupport/lib/active_support/core_ext/array/grouping.rb @@ -100,17 +100,13 @@ class Array results end else - results, arr = [[]], self.dup - until arr.empty? - if (idx = arr.index(value)) - results.last.concat(arr.shift(idx)) - arr.shift - results << [] - else - results.last.concat(arr.shift(arr.size)) - end + arr = self.dup + result = [] + while (idx = arr.index(value)) + result << arr.shift(idx) + arr.shift end - results + result << arr end end end -- cgit v1.2.3