From aa0f4b582eaf225c6ba145eb893fd7b8250a595f Mon Sep 17 00:00:00 2001 From: Grant Hollingworth Date: Tue, 10 Jun 2008 11:54:58 -0400 Subject: [PATCH] faster implementation of Hash#except If there are many keys passed, calling include? on each one is very slow. Not so important within the framework, but this is a core extension that gets used elsewhere. --- .../lib/active_support/core_ext/hash/except.rb | 7 ++++--- 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 8362cd8..768b4aa 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) } + self.clone.except!(*keys) end # Replaces the hash without only the given keys. def except!(*keys) - replace(except(*keys)) + rejected = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) + rejected.each {|key| delete(key) } + self end end end -- 1.5.5.1