From 634e462a0b70ddae2f21dbddddd07e7b340bb69c Mon Sep 17 00:00:00 2001 From: Grant Hollingworth Date: Tue, 10 Jun 2008 11:54:58 -0400 Subject: Performance: speed up Hash#except. [#382 state:resolved] --- activesupport/lib/active_support/core_ext/hash/except.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/core_ext/hash/except.rb b/activesupport/lib/active_support/core_ext/hash/except.rb index 8362cd880e..bc97fa35a6 100644 --- a/activesupport/lib/active_support/core_ext/hash/except.rb +++ b/activesupport/lib/active_support/core_ext/hash/except.rb @@ -10,13 +10,14 @@ module ActiveSupport #:nodoc: module Except # Returns a new hash without the given keys. def except(*keys) - rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) - reject { |key,| rejected.include?(key) } + clone.except!(*keys) end # Replaces the hash without only the given keys. def except!(*keys) - replace(except(*keys)) + keys.map! { |key| convert_key(key) } if respond_to?(:convert_key) + keys.each { |key| delete(key) } + self end end end -- cgit v1.2.3