Skip to content

Commit e6175df

Browse files
committed
Only iterate path_parameters once
`#each_pair` showed up as ~2.5% of a profile, this eliminates it by inlining the iteration into the initial path_parameter construction.
1 parent f9bed92 commit e6175df

File tree

1 file changed

+4
-5
lines changed
  • actionpack/lib/action_dispatch/journey

1 file changed

+4
-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,10 +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
42-
parameters.each_pair { |key, val|
43-
tmp_params[key] = val.force_encoding(::Encoding::UTF_8)
44-
}
41+
tmp_params = set_params.merge route.defaults, parameters
4542

4643
req.path_parameters = tmp_params
4744
req.route = route
@@ -131,11 +128,13 @@ def find_routes(req)
131128
index = 1
132129
match_data.names.each do |name|
133130
if val = match_data[index]
134-
path_parameters[name.to_sym] = if val.include?("%")
131+
val = if val.include?("%")
135132
CGI.unescapeURIComponent(val)
136133
else
137134
val
138135
end
136+
val.force_encoding(::Encoding::UTF_8)
137+
path_parameters[name.to_sym] = val
139138
end
140139
index += 1
141140
end

0 commit comments

Comments
 (0)