aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2015-07-24 23:19:15 -0500
committerschneems <richard.schneeman@gmail.com>2015-07-29 20:41:57 -0500
commit0cbec58ae48279ae5e9fdf6bbdbceb32183215dd (patch)
tree1bed3550b55f63e39b9575e4ab4fb98b55742968
parent097ec6fb7c7e1854cdd96113213b555ae7415953 (diff)
downloadrails-0cbec58ae48279ae5e9fdf6bbdbceb32183215dd.tar.gz
rails-0cbec58ae48279ae5e9fdf6bbdbceb32183215dd.tar.bz2
rails-0cbec58ae48279ae5e9fdf6bbdbceb32183215dd.zip
Decrease route_set allocations
In handle_positional_args `Array#-=` is used which allocates a new array. Instead we can iterate through and delete elements, modifying the array in place. Also `Array#take` allocates a new array. We can build the same by iterating over the other element. This change buys us 106,470 bytes of memory and 2,663 fewer objects per request.
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 42512cad91..43e35366a9 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -267,9 +267,13 @@ module ActionDispatch
path_params -= controller_options.keys
path_params -= result.keys
end
- path_params -= inner_options.keys
- path_params.take(args.size).each do |param|
- result[param] = args.shift
+ inner_options.each do |key, _|
+ path_params.delete(key)
+ end
+
+ args.each_with_index do |arg, index|
+ param = path_params[index]
+ result[param] = arg if param
end
end