提交 df81f2e5 编写于 作者: R Ryuta Kamizono

Use `transform_values` to avoid extra Array allocation

上级 dc06d4bf
......@@ -65,15 +65,15 @@ def relative_path?(path)
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 @@ def process_hash(value)
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 @@ def *(*)
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 @@ def to_s
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)$/)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册