diff options
author | Xavier Noria <fxn@hashref.com> | 2014-11-18 12:00:05 +0100 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2014-11-18 12:00:05 +0100 |
commit | 4fc493ff7ef3e44ae8691ff5ae3b80be540f09d1 (patch) | |
tree | 5db6c52a5378e2a0f2df6ca54d351a22ef043aad | |
parent | 3098579f276d5cecbca0b57e35526b99fadfbe5f (diff) | |
parent | 9aa2b2d7bf52c0f3974090cd033341be2edeae6d (diff) | |
download | rails-4fc493ff7ef3e44ae8691ff5ae3b80be540f09d1.tar.gz rails-4fc493ff7ef3e44ae8691ff5ae3b80be540f09d1.tar.bz2 rails-4fc493ff7ef3e44ae8691ff5ae3b80be540f09d1.zip |
Merge pull request #17658 from SamSaffron/optimise_memory
PERF: stop allocating the string "id" over and over
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/read.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb index bf2a084a00..55beb309ca 100644 --- a/activerecord/lib/active_record/attribute_methods/read.rb +++ b/activerecord/lib/active_record/attribute_methods/read.rb @@ -76,12 +76,14 @@ module ActiveRecord end end + ID = 'id'.freeze + # Returns the value of the attribute identified by <tt>attr_name</tt> after # it has been typecast (for example, "2004-12-12" in a date column is cast # to a date object, like Date.new(2004, 12, 12)). def read_attribute(attr_name, &block) name = attr_name.to_s - name = self.class.primary_key if name == 'id' + name = self.class.primary_key if name == ID @attributes.fetch_value(name, &block) end |