From 0755d300170d1ef2f6d78f76d0126e962167be5a Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 20 Mar 2015 08:09:53 -0400 Subject: Use fullpath from Rack request rather than building it In Rack, `#fullpath` checks if there is a query string and builds the query correctly: ``` def path script_name + path_info end def fullpath query_string.empty? ? path : "#{path}?#{query_string}" end ``` We can utilize this instead of manually building the fullpath because they are the same result. This also reduces allocations in `#call` because we don't need `build_original_fullpath` to create the paths and query strings. We don't need to build `fullpath` twice. --- railties/lib/rails/application.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index ff6c905f3e..ad6ec1264d 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -159,8 +159,9 @@ module Rails # Implements call according to the Rack API. It simply # dispatches the request to the underlying middleware stack. def call(env) - env["ORIGINAL_FULLPATH"] = build_original_fullpath(env) - env["ORIGINAL_SCRIPT_NAME"] = env["SCRIPT_NAME"] + req = ActionDispatch::Request.new env + env["ORIGINAL_FULLPATH"] = req.fullpath + env["ORIGINAL_SCRIPT_NAME"] = req.script_name super(env) end @@ -505,15 +506,8 @@ module Rails end def build_original_fullpath(env) #:nodoc: - path_info = env["PATH_INFO"] - query_string = env["QUERY_STRING"] - script_name = env["SCRIPT_NAME"] - - if query_string.present? - "#{script_name}#{path_info}?#{query_string}" - else - "#{script_name}#{path_info}" - end + req = ActionDispatch::Request.new env + env["ORIGINAL_FULLPATH"] = req.fullpath end def validate_secret_key_config! #:nodoc: -- cgit v1.2.3