Skip to content

Commit dc45cb8

Browse files
committed
Construct path_parameters from merged hash
This saves a hash allocation as well as the time to copy the path_parameters from the temporary hash to the final hash.
1 parent e6175df commit dc45cb8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

actionpack/lib/action_dispatch/journey/router.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ def serve(req)
3838
req.path_info = "/" + req.path_info unless req.path_info.start_with? "/"
3939
end
4040

41-
tmp_params = set_params.merge route.defaults, parameters
42-
43-
req.path_parameters = tmp_params
41+
req.path_parameters = parameters
4442
req.route = route
4543

4644
_, headers, _ = response = route.app.serve(req)
@@ -66,7 +64,6 @@ def recognize(rails_req)
6664
rails_req.path_info = "/" + rails_req.path_info unless rails_req.path_info.start_with? "/"
6765
end
6866

69-
parameters = route.defaults.merge parameters
7067
yield(route, parameters)
7168
end
7269
end
@@ -124,7 +121,9 @@ def find_routes(req)
124121

125122
routes.each do |r|
126123
match_data = r.path.match(path_info)
127-
path_parameters = {}
124+
125+
path_parameters = req.path_parameters.merge r.defaults
126+
128127
index = 1
129128
match_data.names.each do |name|
130129
if val = match_data[index]

actionpack/lib/action_dispatch/routing/route_set.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ def recognize_path_with_request(req, path, extras, raise_on_missing: true)
932932
params[key] = URI::RFC2396_PARSER.unescape(value)
933933
end
934934
end
935+
original_path_parameters = req.path_parameters
935936
req.path_parameters = params
936937
app = route.app
937938
if app.matches?(req) && app.dispatcher?
@@ -945,6 +946,8 @@ def recognize_path_with_request(req, path, extras, raise_on_missing: true)
945946
elsif app.matches?(req) && app.engine?
946947
path_parameters = app.rack_app.routes.recognize_path_with_request(req, path, extras, raise_on_missing: false)
947948
return path_parameters if path_parameters
949+
else
950+
req.path_parameters = original_path_parameters
948951
end
949952
end
950953

0 commit comments

Comments
 (0)