aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorGrant Hollingworth <grant@antiflux.org>2008-06-10 11:54:58 -0400
committerJeremy Kemper <jeremy@bitsweat.net>2008-06-11 00:47:02 -0700
commit634e462a0b70ddae2f21dbddddd07e7b340bb69c (patch)
tree1bdddcac017c4bcd328ae4e97fd1e9a8ef4c6dad /activesupport
parente8a0ba4c93e2f0f811675bc6a6720725c866d1a5 (diff)
downloadrails-634e462a0b70ddae2f21dbddddd07e7b340bb69c.tar.gz
rails-634e462a0b70ddae2f21dbddddd07e7b340bb69c.tar.bz2
rails-634e462a0b70ddae2f21dbddddd07e7b340bb69c.zip
Performance: speed up Hash#except. [#382 state:resolved]
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/except.rb7
1 files changed, 4 insertions, 3 deletions
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