mirror of
https://github.com/github/rails.git
synced 2026-01-29 08:18:03 -05:00
Faster Hash#slice that doesn't use Enumerable#include?.
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
committed by
Jeremy Kemper
parent
714d42d1a6
commit
952ec79bec
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user