mirror of
https://github.com/github/rails.git
synced 2026-01-28 07:48:00 -05:00
Performance: minor Array#to_param and #to_query speedups
This commit is contained in:
@@ -27,7 +27,7 @@ module ActiveSupport #:nodoc:
|
||||
# Calls <tt>to_param</tt> on all its elements and joins the result with
|
||||
# slashes. This is used by <tt>url_for</tt> in Action Pack.
|
||||
def to_param
|
||||
map(&:to_param).join '/'
|
||||
collect { |e| e.to_param }.join '/'
|
||||
end
|
||||
|
||||
# Converts an array into a string suitable for use as a URL query string,
|
||||
@@ -35,7 +35,8 @@ module ActiveSupport #:nodoc:
|
||||
#
|
||||
# ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
|
||||
def to_query(key)
|
||||
collect { |value| value.to_query("#{key}[]") } * '&'
|
||||
prefix = "#{key}[]"
|
||||
collect { |value| value.to_query(prefix) }.join '&'
|
||||
end
|
||||
|
||||
def self.included(base) #:nodoc:
|
||||
|
||||
Reference in New Issue
Block a user