From 75a2ca6e9dca2c36d80478bcc78ac7bd25bf38f7 Mon Sep 17 00:00:00 2001 From: Miles Georgi Date: Thu, 6 Dec 2018 19:37:00 +0000 Subject: HashWithIndifferentAccess#initialize performance improvement Rails 4 -> Rails 5 introduced a #to_hash call in HashWithIndifferentAccess#initialize to guarantee access to the #default and #default_proc methods. This can be a very expensive operation for very large HashWithIndifferentAccess objects. This commit bypasses this #to_hash call if it is already a Hash. --- activesupport/lib/active_support/hash_with_indifferent_access.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index f1af76019a..aa81ad6250 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -69,7 +69,7 @@ module ActiveSupport super() update(constructor) - hash = constructor.to_hash + hash = constructor.is_a?(Hash) ? constructor : constructor.to_hash self.default = hash.default if hash.default self.default_proc = hash.default_proc if hash.default_proc else -- cgit v1.2.3