mirror of
https://github.com/github/rails.git
synced 2026-02-01 09:44:56 -05:00
Performance: speed up Hash#except. [#382 state:resolved]
This commit is contained in:
committed by
Jeremy Kemper
parent
e8a0ba4c93
commit
634e462a0b
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user