aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorMichael Lovitt <michael@lovitt.net>2017-05-25 17:14:33 -0500
committerMichael Lovitt <michael@lovitt.net>2017-05-25 17:14:33 -0500
commitfb6ccce80663dad034d86c472024076a8348a12f (patch)
treeef93559e4f46edab760f64f0cf387a21ac6c47c5 /activerecord
parent63dd12b7b83541d8a469a8e6aed1607d77f0d994 (diff)
downloadrails-fb6ccce80663dad034d86c472024076a8348a12f.tar.gz
rails-fb6ccce80663dad034d86c472024076a8348a12f.tar.bz2
rails-fb6ccce80663dad034d86c472024076a8348a12f.zip
Make #deep_dup use #allocate instead of #new
This change preserves the speedup made in a24912cb1d3 (by avoiding the wasted shallow dup of @attributes) while ensuring that the performance of #deep_dup won't be tied to the performance of #initialize
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_set.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_set.rb b/activerecord/lib/active_record/attribute_set.rb
index abe8e14f26..01f9d815d5 100644
--- a/activerecord/lib/active_record/attribute_set.rb
+++ b/activerecord/lib/active_record/attribute_set.rb
@@ -64,7 +64,9 @@ module ActiveRecord
end
def deep_dup
- self.class.new(attributes.deep_dup)
+ self.class.allocate.tap do |copy|
+ copy.instance_variable_set(:@attributes, attributes.deep_dup)
+ end
end
def initialize_dup(_)