From 952ec79bec313e0001adfc8c86f7970448d32db9 Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Mon, 2 Jun 2008 01:42:38 -0700 Subject: Faster Hash#slice that doesn't use Enumerable#include?. Signed-off-by: Jeremy Kemper --- activesupport/lib/active_support/core_ext/hash/slice.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb index 6fe5e05330..44b6964c69 100644 --- a/activesupport/lib/active_support/core_ext/hash/slice.rb +++ b/activesupport/lib/active_support/core_ext/hash/slice.rb @@ -15,7 +15,9 @@ module ActiveSupport #:nodoc: # Returns a new hash with only the given keys. def slice(*keys) allowed = Set.new(respond_to?(:convert_key) ? keys.map { |key| convert_key(key) } : keys) - reject { |key,| !allowed.include?(key) } + hash = {} + allowed.each { |k| hash[k] = self[k] } + hash end # Replaces the hash with only the given keys. -- cgit v1.2.3