Skip to content

Commit d577019

Browse files
committed
Skip get_header and set_header for hot methods on Request
That extra method call is very costly for what is just meant to be a hash lookup.
1 parent 8297332 commit d577019

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

actionpack/lib/action_dispatch/http/parameters.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def parameters
6565
alias :params :parameters
6666

6767
def path_parameters=(parameters) # :nodoc:
68-
delete_header("action_dispatch.request.parameters")
68+
@env.delete("action_dispatch.request.parameters")
6969

7070
parameters = Request::Utils.set_binary_encoding(self, parameters, parameters[:controller], parameters[:action])
7171
# If any of the path parameters has an invalid encoding then raise since it's
7272
# likely to trigger errors further on.
7373
Request::Utils.check_param_encoding(parameters)
7474

75-
set_header PARAMETERS_KEY, parameters
75+
@env[PARAMETERS_KEY] = parameters
7676
rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e
7777
raise ActionController::BadRequest.new("Invalid path parameters: #{e.message}")
7878
end
@@ -82,7 +82,7 @@ def path_parameters=(parameters) # :nodoc:
8282
#
8383
# { action: "my_action", controller: "my_controller" }
8484
def path_parameters
85-
get_header(PARAMETERS_KEY) || set_header(PARAMETERS_KEY, {})
85+
@env[PARAMETERS_KEY] ||= {}
8686
end
8787

8888
private

actionpack/lib/action_dispatch/http/request.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def route_uri_pattern
166166
end
167167

168168
def route=(route) # :nodoc:
169-
set_header("action_dispatch.route", route)
169+
@env["action_dispatch.route"] = route
170170
end
171171

172172
def routes # :nodoc:

0 commit comments

Comments
 (0)