Permalink
Browse files

Remove array allocation

THe only reason we were allocating an array is to get the "missing_keys" variable in scope of the error message generator. Guess what? Arrays kinda take up a lot of memory, so by replacing that with a nil, we save:

35,303 bytes and 886 objects per request
  • Loading branch information...
schneems committed Jul 27, 2015
1 parent 005541b commit 4d2ccc119cac2dc2757d3d977059feba9db858d2
Showing with 2 additions and 2 deletions.
  1. +2 −2 actionpack/lib/action_dispatch/journey/formatter.rb
@@ -14,7 +14,7 @@ def initialize(routes)
def generate(name, options, path_parameters, parameterize = nil)
constraints = path_parameters.merge(options)
missing_keys = []
missing_keys = nil # need for variable scope
match_route(name, constraints) do |route|
parameterized_parts = extract_parameterized_parts(route, options, path_parameters, parameterize)
@@ -40,7 +40,7 @@ def generate(name, options, path_parameters, parameterize = nil)
end
message = "No route matches #{Hash[constraints.sort_by{|k,v| k.to_s}].inspect}"
message << " missing required keys: #{missing_keys.sort.inspect}" unless missing_keys.empty?
message << " missing required keys: #{missing_keys.sort.inspect}" if missing_keys && missing_keys.any?
raise ActionController::UrlGenerationError, message
end

0 comments on commit 4d2ccc1

Please sign in to comment.