Use `transform_values` to avoid extra Array allocation

This commit is contained in:
Ryuta Kamizono 2020-01-27 11:03:35 +09:00
parent dc06d4bfb0
commit df81f2e5f5
4 changed files with 6 additions and 6 deletions

View File

@ -65,15 +65,15 @@ module ActionDispatch
end
def escape(params)
Hash[params.map { |k, v| [k, Rack::Utils.escape(v)] }]
params.transform_values { |v| Rack::Utils.escape(v) }
end
def escape_fragment(params)
Hash[params.map { |k, v| [k, Journey::Router::Utils.escape_fragment(v)] }]
params.transform_values { |v| Journey::Router::Utils.escape_fragment(v) }
end
def escape_path(params)
Hash[params.map { |k, v| [k, Journey::Router::Utils.escape_path(v)] }]
params.transform_values { |v| Journey::Router::Utils.escape_path(v) }
end
end

View File

@ -208,7 +208,7 @@ module ActiveSupport
elsif become_empty_string?(value)
""
elsif become_hash?(value)
xml_value = Hash[value.map { |k, v| [k, deep_to_h(v)] }]
xml_value = value.transform_values { |v| deep_to_h(v) }
# Turn { files: { file: #<StringIO> } } into { files: #<StringIO> } so it is compatible with
# how multipart uploaded files from HTML appear

View File

@ -222,7 +222,7 @@ module ActiveSupport #:nodoc:
def %(args)
case args
when Hash
escaped_args = Hash[args.map { |k, arg| [k, html_escape_interpolated_argument(arg)] }]
escaped_args = args.transform_values { |arg| html_escape_interpolated_argument(arg) }
else
escaped_args = Array(args).map { |arg| html_escape_interpolated_argument(arg) }
end

View File

@ -35,7 +35,7 @@ class CodeStatistics #:nodoc:
private
def calculate_statistics
Hash[@pairs.map { |pair| [pair.first, calculate_directory_statistics(pair.last)] }]
@pairs.transform_values { |dir| calculate_directory_statistics(dir) }
end
def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|coffee|rake)$/)