diff options
author | Aaron Patterson <tenderlove@github.com> | 2018-06-26 14:16:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-26 14:16:06 -0700 |
commit | 316513177cf9033d842cc176f8401d4e7c7e7c2a (patch) | |
tree | b926c2867ec04e98d43249704ebbef43d5456ee5 /activerecord/lib/active_record/core.rb | |
parent | a399d96ed4576f429cf6f809110bf6c0fa67bb7d (diff) | |
parent | 1cec4e1bbaba786aa4ea70a0e2b6ad6f15ec1e68 (diff) | |
download | rails-316513177cf9033d842cc176f8401d4e7c7e7c2a.tar.gz rails-316513177cf9033d842cc176f8401d4e7c7e7c2a.tar.bz2 rails-316513177cf9033d842cc176f8401d4e7c7e7c2a.zip |
Merge pull request #33223 from rails/homogeneous-allocation
Speed up homogeneous AR lists / reduce allocations
Diffstat (limited to 'activerecord/lib/active_record/core.rb')
-rw-r--r-- | activerecord/lib/active_record/core.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index e03c86f48c..df795df52e 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -345,6 +345,28 @@ module ActiveRecord end ## + # Initializer used for instantiating objects that have been read from the + # database. +attributes+ should be an attributes object, and unlike the + # `initialize` method, no assignment calls are made per attribute. + # + # :nodoc: + def init_from_db(attributes) + init_internals + + @new_record = false + @attributes = attributes + + self.class.define_attribute_methods + + yield self if block_given? + + _run_find_callbacks + _run_initialize_callbacks + + self + end + + ## # :method: clone # Identical to Ruby's clone method. This is a "shallow" copy. Be warned that your attributes are not copied. # That means that modifying attributes of the clone will modify the original, since they will both point to the |