aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2015-07-25 00:25:47 -0500
committerschneems <richard.schneeman@gmail.com>2015-07-30 12:30:47 -0500
commitbff61ba27cb113b90f210a30173a8e66602615ca (patch)
tree691c5a1d5b64913514d5bab90cd1655b96aa6778 /actionpack/lib/action_dispatch
parente76a84350595ca6772d3c00f456b35e411fba6c1 (diff)
downloadrails-bff61ba27cb113b90f210a30173a8e66602615ca.tar.gz
rails-bff61ba27cb113b90f210a30173a8e66602615ca.tar.bz2
rails-bff61ba27cb113b90f210a30173a8e66602615ca.zip
Avoid calling to_s on nil in journey/formatter
When `defaults[key]` in `generate` in the journey formatter is called, it often returns a `nil` when we call `to_s` on a nil, it allocates an empty string. We can skip this check when the default value is nil. This change buys us 35,431 bytes of memory and 887 fewer objects per request. Thanks to @matthewd for help with the readability
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/journey/formatter.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb
index 985cf8b947..95e1d2deb2 100644
--- a/actionpack/lib/action_dispatch/journey/formatter.rb
+++ b/actionpack/lib/action_dispatch/journey/formatter.rb
@@ -32,8 +32,8 @@ module ActionDispatch
defaults = route.defaults
required_parts = route.required_parts
- parameterized_parts.delete_if do |key, value|
- value.to_s == defaults[key].to_s && !required_parts.include?(key)
+ parameterized_parts.keep_if do |key, value|
+ defaults[key].nil? || value.to_s != defaults[key].to_s || required_parts.include?(key)
end
return [route.format(parameterized_parts), params]