diff options
author | schneems <richard.schneeman@gmail.com> | 2015-07-27 01:52:45 -0500 |
---|---|---|
committer | schneems <richard.schneeman@gmail.com> | 2015-07-30 12:31:05 -0500 |
commit | 61dae882546f643050c47e573161a467e156c704 (patch) | |
tree | 8dd7e181701b7aa5365b8d5e6bbf7040cf92b0e5 /actionpack/lib | |
parent | 4d2ccc119cac2dc2757d3d977059feba9db858d2 (diff) | |
download | rails-61dae882546f643050c47e573161a467e156c704.tar.gz rails-61dae882546f643050c47e573161a467e156c704.tar.bz2 rails-61dae882546f643050c47e573161a467e156c704.zip |
Remove (another) array allocation
We don't always need an array when generating a url with the formatter. We can be lazy about allocating the `missing_keys` array. This saves us:
35,606 bytes and 889 objects per request
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/formatter.rb | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index 7b091a35ab..d6daf5280b 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -25,7 +25,7 @@ module ActionDispatch next unless name || route.dispatcher? missing_keys = missing_keys(route, parameterized_parts) - next unless missing_keys.empty? + next if missing_keys && missing_keys.any? params = options.dup.delete_if do |key, _| parameterized_parts.key?(key) || route.defaults.key?(key) end @@ -122,16 +122,25 @@ module ActionDispatch # Returns an array populated with missing keys if any are present. def missing_keys(route, parts) - missing_keys = [] + missing_keys = nil tests = route.path.requirements route.required_parts.each { |key| case tests[key] when nil - missing_keys << key unless parts[key] + unless parts[key] + missing_keys ||= [] + missing_keys << key + end when RegexCaseComparator - missing_keys << key unless RegexCaseComparator::DEFAULT_REGEX === parts[key] + unless RegexCaseComparator::DEFAULT_REGEX === parts[key] + missing_keys ||= [] + missing_keys << key + end else - missing_keys << key unless /\A#{tests[key]}\Z/ === parts[key] + unless /\A#{tests[key]}\Z/ === parts[key] + missing_keys ||= [] + missing_keys << key + end end } missing_keys |