aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorMiles Georgi <azimux@gmail.com>2018-12-06 19:37:00 +0000
committerMiles Georgi <azimux@gmail.com>2018-12-06 20:16:43 +0000
commit75a2ca6e9dca2c36d80478bcc78ac7bd25bf38f7 (patch)
tree713bb771b6eb323fc9da80f9ce83c3c1e0c963a5 /activesupport/lib
parentb86f65a816546ff8eea39d25b62c995c7efc21dc (diff)
downloadrails-75a2ca6e9dca2c36d80478bcc78ac7bd25bf38f7.tar.gz
rails-75a2ca6e9dca2c36d80478bcc78ac7bd25bf38f7.tar.bz2
rails-75a2ca6e9dca2c36d80478bcc78ac7bd25bf38f7.zip
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.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/hash_with_indifferent_access.rb2
1 files changed, 1 insertions, 1 deletions
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