From 32db884967a8af0409bfcb2158ee948cd7ef619c Mon Sep 17 00:00:00 2001 From: Timo Schilling Date: Wed, 27 Mar 2019 21:18:18 +0100 Subject: Speed improvement for Hash#except --- activesupport/lib/active_support/core_ext/hash/except.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/hash/except.rb b/activesupport/lib/active_support/core_ext/hash/except.rb index 6258610c98..5013812460 100644 --- a/activesupport/lib/active_support/core_ext/hash/except.rb +++ b/activesupport/lib/active_support/core_ext/hash/except.rb @@ -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. -- cgit v1.2.3 From a805d72e901f81f5b043dfd9904b80ce93ebfc01 Mon Sep 17 00:00:00 2001 From: Timo Schilling Date: Wed, 27 Mar 2019 21:54:30 +0100 Subject: Speed improvement for HashWithIndifferentAccess#except --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 3a2b2652c4..a4e366f80f 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -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 -- cgit v1.2.3 From 9f41edb535ae43faeadc4ef6d16e459435b170e0 Mon Sep 17 00:00:00 2001 From: Timo Schilling Date: Tue, 2 Apr 2019 14:04:11 +0200 Subject: Speed improvement for HashWithIndifferentAccess#fetch_values --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index a4e366f80f..e0117dacfc 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -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. -- cgit v1.2.3 From 49598c0638b8f8afeb10b20cf64ff83a2ea1d8b2 Mon Sep 17 00:00:00 2001 From: Timo Schilling Date: Tue, 2 Apr 2019 11:48:39 +0200 Subject: Speed improvement for HashWithIndifferentAccess#values_at --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index e0117dacfc..42ae7e9b7b 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -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 -- cgit v1.2.3