1
0
Fork 0
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:
Rafael França 2019-04-02 17:28:50 -04:00 committed by GitHub
commit 736c7d5995
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View file

@ -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.

View file

@ -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