Permalink
Browse files

Avoid deep_dup when intantiating.

deep_dup is slow. we only need to dup the values, so just do that
directly.
  • Loading branch information...
1 parent 3e8ab91 commit 1b2c907727e4a698d9c2979958aa78a1b4bfdaa1 @jonleighton jonleighton committed Aug 17, 2012
Showing with 5 additions and 2 deletions.
  1. +5 −2 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 @@ def relation #:nodoc:
# # 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

0 comments on commit 1b2c907

Please sign in to comment.