aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorViktar Basharymau <viktar.basharymau@gmail.com>2016-01-02 18:42:15 +0300
committerViktar Basharymau <viktar.basharymau@gmail.com>2016-01-02 19:34:40 +0300
commit20aef99f7bd136f156bf4b3808626398013f22f5 (patch)
treea062ed5b066c12ed7edd3ca1663961ebdc02d782 /actionpack
parenta0a62da235e8d87795d6cef6613ddf440386b366 (diff)
downloadrails-20aef99f7bd136f156bf4b3808626398013f22f5.tar.gz
rails-20aef99f7bd136f156bf4b3808626398013f22f5.tar.bz2
rails-20aef99f7bd136f156bf4b3808626398013f22f5.zip
Replace x.times.map{} with Array.new(x){}
The former is slightly more readable, performant and has fewer method calls. ```ruby Benchmark.ips do |x| x.report('times.map') { 5.times.map{} } x.report('Array.new') { Array.new(5){} } x.compare! end __END__ Calculating ------------------------------------- times.map 21.188k i/100ms Array.new 30.449k i/100ms ------------------------------------------------- times.map 311.613k (± 3.5%) i/s - 1.568M Array.new 590.374k (± 1.2%) i/s - 2.954M Comparison: Array.new: 590373.6 i/s times.map: 311612.8 i/s - 1.89x slower ```
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/journey/path/pattern.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/journey/path/pattern.rb b/actionpack/lib/action_dispatch/journey/path/pattern.rb
index 5ee8810066..018b89a2b7 100644
--- a/actionpack/lib/action_dispatch/journey/path/pattern.rb
+++ b/actionpack/lib/action_dispatch/journey/path/pattern.rb
@@ -124,7 +124,7 @@ module ActionDispatch
end
def captures
- (length - 1).times.map { |i| self[i + 1] }
+ Array.new(length - 1) { |i| self[i + 1] }
end
def [](x)