aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-08-17 15:58:13 +0100
committerJon Leighton <j@jonathanleighton.com>2012-08-17 18:22:29 +0100
commit1b2c907727e4a698d9c2979958aa78a1b4bfdaa1 (patch)
treebc4c16ccd370129a7c185b8bb29875fb52bf48c2 /activerecord
parent3e8ab910ce636c9980d4fd9bc9aade795fd578ef (diff)
downloadrails-1b2c907727e4a698d9c2979958aa78a1b4bfdaa1.tar.gz
rails-1b2c907727e4a698d9c2979958aa78a1b4bfdaa1.tar.bz2
rails-1b2c907727e4a698d9c2979958aa78a1b4bfdaa1.zip
Avoid deep_dup when intantiating.
deep_dup is slow. we only need to dup the values, so just do that directly.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/core.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index 0fddfdf0cb..e35f952151 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -1,5 +1,5 @@
require 'active_support/core_ext/hash/indifferent_access'
-require 'active_support/core_ext/object/deep_dup'
+require 'active_support/core_ext/object/duplicable'
require 'thread'
module ActiveRecord
@@ -173,7 +173,10 @@ module ActiveRecord
# # Instantiates a single new object bypassing mass-assignment security
# User.new({ :first_name => 'Jamie', :is_admin => true }, :without_protection => true)
def initialize(attributes = nil, options = {})
- @attributes = self.class.initialize_attributes(self.class.column_defaults.deep_dup)
+ defaults = self.class.column_defaults.dup
+ defaults.each { |k, v| defaults[k] = v.dup if v.duplicable? }
+
+ @attributes = self.class.initialize_attributes(defaults)
@columns_hash = self.class.column_types.dup
init_internals