mirror of https://github.com/rails/rails
Use `transform_values` to avoid extra Array allocation
This commit is contained in:
parent
dc06d4bfb0
commit
df81f2e5f5
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)$/)
|
||||
|
|
Loading…
Reference in New Issue