aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/core.rb
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@github.com>2018-06-26 14:16:06 -0700
committerGitHub <noreply@github.com>2018-06-26 14:16:06 -0700
commit316513177cf9033d842cc176f8401d4e7c7e7c2a (patch)
treeb926c2867ec04e98d43249704ebbef43d5456ee5 /activerecord/lib/active_record/core.rb
parenta399d96ed4576f429cf6f809110bf6c0fa67bb7d (diff)
parent1cec4e1bbaba786aa4ea70a0e2b6ad6f15ec1e68 (diff)
downloadrails-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.rb22
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