aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2015-07-24 22:38:34 -0500
committerschneems <richard.schneeman@gmail.com>2015-07-29 20:41:57 -0500
commit9b8258814e695fe7fbb728456498fd0fd8709f5c (patch)
tree00f25ca7276928946dc7b8cefc8d44f6a974ef92 /actionpack/lib
parent83ee043c6834914607849ae9cd3b9eab6b41702c (diff)
downloadrails-9b8258814e695fe7fbb728456498fd0fd8709f5c.tar.gz
rails-9b8258814e695fe7fbb728456498fd0fd8709f5c.tar.bz2
rails-9b8258814e695fe7fbb728456498fd0fd8709f5c.zip
Speed up journey extract_parameterized_parts
Micro optimization: `reverse.drop_while` is slower than `reverse_each.drop_while`. This doesn't save any object allocations. Second, `keys_to_keep` is typically a very small array. The operation `parameterized_parts.keys - keys_to_keep` actually allocates two arrays. It is quicker (I benchmarked) to iterate over each and check inclusion in array manually. This change buys us 1774 fewer objects per request
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_dispatch/journey/formatter.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb
index c0566c6fc9..545b67422d 100644
--- a/actionpack/lib/action_dispatch/journey/formatter.rb
+++ b/actionpack/lib/action_dispatch/journey/formatter.rb
@@ -54,11 +54,12 @@ module ActionDispatch
def extract_parameterized_parts(route, options, recall, parameterize = nil)
parameterized_parts = recall.merge(options)
- keys_to_keep = route.parts.reverse.drop_while { |part|
+ keys_to_keep = route.parts.reverse_each.drop_while { |part|
!options.key?(part) || (options[part] || recall[part]).nil?
} | route.required_parts
- (parameterized_parts.keys - keys_to_keep).each do |bad_key|
+ parameterized_parts.each do |bad_key, _|
+ next if keys_to_keep.include?(bad_key)
parameterized_parts.delete(bad_key)
end