diff options
author | KD <kd.engineer@yahoo.co.in> | 2013-11-11 12:42:40 +0530 |
---|---|---|
committer | KD <kd.engineer@yahoo.co.in> | 2013-11-11 13:31:26 +0530 |
commit | 4aadd160ff96839e2e87399ab90f85437b1218a8 (patch) | |
tree | c6bb041e4f8e438f7f3dddb955992a9b89b3d28d /activesupport | |
parent | 133399482c12820c6c96c5e0e6697cdcc0f158e3 (diff) | |
download | rails-4aadd160ff96839e2e87399ab90f85437b1218a8.tar.gz rails-4aadd160ff96839e2e87399ab90f85437b1218a8.tar.bz2 rails-4aadd160ff96839e2e87399ab90f85437b1218a8.zip |
Speed up Array#split
Ruby 2.0.0p247
Rehearsal ---------------------------------------
old 10.670000 0.150000 10.820000 ( 10.822651)
new 8.520000 0.050000 8.570000 ( 8.571825)
----------------------------- total: 19.390000sec
user system total real
old 10.620000 0.170000 10.790000 ( 10.790409)
new 8.570000 0.110000 8.680000 ( 8.686051)
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/grouping.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/grouping.rb b/activesupport/lib/active_support/core_ext/array/grouping.rb index c0d6e5b70c..217a147e80 100644 --- a/activesupport/lib/active_support/core_ext/array/grouping.rb +++ b/activesupport/lib/active_support/core_ext/array/grouping.rb @@ -83,10 +83,10 @@ class Array # # [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]] # (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]] - def split(value = nil, &block) - if block + def split(value = nil) + if block_given? inject([[]]) do |results, element| - if block.call(element) + if yield(element) results << [] else results.last << element |