From fb6ccce80663dad034d86c472024076a8348a12f Mon Sep 17 00:00:00 2001 From: Michael Lovitt Date: Thu, 25 May 2017 17:14:33 -0500 Subject: 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 --- activerecord/lib/active_record/attribute_set.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib') 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(_) -- cgit v1.2.3