aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2015-07-24 22:32:01 -0500
committerschneems <richard.schneeman@gmail.com>2015-07-29 20:41:57 -0500
commit83ee043c6834914607849ae9cd3b9eab6b41702c (patch)
tree06994e7775e6ba8d685bc0c813484b225d315bcb
parent1bf50badd943e684a56a03392ef0ddafefca0ad7 (diff)
downloadrails-83ee043c6834914607849ae9cd3b9eab6b41702c.tar.gz
rails-83ee043c6834914607849ae9cd3b9eab6b41702c.tar.bz2
rails-83ee043c6834914607849ae9cd3b9eab6b41702c.zip
Decrease string allocations in url_options
The request.script_name is dup-d which allocates an extra string. It is most commonly an empty string "". We can save a ton of string allocations by checking first if the string is empty, if so we can use a frozen empty string instead of duplicating an empty string. This change buys us 35,714 bytes of memory and 893 fewer objects per request.
-rw-r--r--actionpack/lib/action_controller/metal/url_for.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb
index 5a0e5c62e4..dbf7241a14 100644
--- a/actionpack/lib/action_controller/metal/url_for.rb
+++ b/actionpack/lib/action_controller/metal/url_for.rb
@@ -41,7 +41,11 @@ module ActionController
if original_script_name
options[:original_script_name] = original_script_name
else
- options[:script_name] = same_origin ? request.script_name.dup : script_name
+ if same_origin
+ options[:script_name] = request.script_name.empty? ? "".freeze : request.script_name.dup
+ else
+ options[:script_name] = script_name
+ end
end
options.freeze
else