Permalink
Browse files

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

  • Loading branch information...
granth authored and jeremy committed Jun 10, 2008
1 parent e8a0ba4 commit 634e462a0b70ddae2f21dbddddd07e7b340bb69c
Showing with 4 additions and 3 deletions.
  1. +4 −3 activesupport/lib/active_support/core_ext/hash/except.rb
@@ -10,13 +10,14 @@ module Hash #: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

0 comments on commit 634e462

Please sign in to comment.