diff options
author | Cheah Chu Yeow <chuyeow@gmail.com> | 2008-06-02 01:42:38 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-06-02 11:47:15 -0700 |
commit | 952ec79bec313e0001adfc8c86f7970448d32db9 (patch) | |
tree | 52d2ce3c0f14232e76ce5267bfe1a62435591f87 /activesupport/lib/active_support/core_ext/hash | |
parent | 714d42d1a6140ac4f6fc478bf1766d2b0aedb251 (diff) | |
download | rails-952ec79bec313e0001adfc8c86f7970448d32db9.tar.gz rails-952ec79bec313e0001adfc8c86f7970448d32db9.tar.bz2 rails-952ec79bec313e0001adfc8c86f7970448d32db9.zip |
Faster Hash#slice that doesn't use Enumerable#include?.
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/lib/active_support/core_ext/hash')
-rw-r--r-- | activesupport/lib/active_support/core_ext/hash/slice.rb | 4 |
1 files changed, 3 insertions, 1 deletions
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. |