mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #35771 from timoschilling/hash-speed-improvements
Hash / HashWithIndifferentAccess speed improvements
This commit is contained in:
commit
736c7d5995
2 changed files with 7 additions and 4 deletions
|
@ -10,7 +10,7 @@ class Hash
|
|||
# This is useful for limiting a set of parameters to everything but a few known toggles:
|
||||
# @person.update(params[:person].except(:admin))
|
||||
def except(*keys)
|
||||
dup.except!(*keys)
|
||||
slice(*self.keys - keys)
|
||||
end
|
||||
|
||||
# Removes the given keys from hash and returns it.
|
||||
|
|
|
@ -225,8 +225,8 @@ module ActiveSupport
|
|||
# hash[:a] = 'x'
|
||||
# hash[:b] = 'y'
|
||||
# hash.values_at('a', 'b') # => ["x", "y"]
|
||||
def values_at(*indices)
|
||||
indices.collect { |key| self[convert_key(key)] }
|
||||
def values_at(*keys)
|
||||
super(*keys.map { |key| convert_key(key) })
|
||||
end
|
||||
|
||||
# Returns an array of the values at the specified indices, but also
|
||||
|
@ -239,7 +239,7 @@ module ActiveSupport
|
|||
# hash.fetch_values('a', 'c') { |key| 'z' } # => ["x", "z"]
|
||||
# hash.fetch_values('a', 'c') # => KeyError: key not found: "c"
|
||||
def fetch_values(*indices, &block)
|
||||
indices.collect { |key| fetch(key, &block) }
|
||||
super(*indices.map { |key| convert_key(key) }, &block)
|
||||
end
|
||||
|
||||
# Returns a shallow copy of the hash.
|
||||
|
@ -293,6 +293,9 @@ module ActiveSupport
|
|||
super(convert_key(key))
|
||||
end
|
||||
|
||||
def except(*keys)
|
||||
slice(*self.keys - keys.map { |key| convert_key(key) })
|
||||
end
|
||||
alias_method :without, :except
|
||||
|
||||
def stringify_keys!; self end
|
||||
|
|
Loading…
Reference in a new issue