Performance: speed up Hash#except. [#382 state:resolved]

This commit is contained in:
Grant Hollingworth
2008-06-10 11:54:58 -04:00
committed by Jeremy Kemper
parent e8a0ba4c93
commit 634e462a0b

View File

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