aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorSam <sam.saffron@gmail.com>2014-11-18 21:38:27 +1100
committerSam <sam.saffron@gmail.com>2014-11-18 21:38:27 +1100
commit9aa2b2d7bf52c0f3974090cd033341be2edeae6d (patch)
tree5db6c52a5378e2a0f2df6ca54d351a22ef043aad /activerecord
parenteb26f24bde62cbbcd8ef0e7ee9c64060b098baff (diff)
downloadrails-9aa2b2d7bf52c0f3974090cd033341be2edeae6d.tar.gz
rails-9aa2b2d7bf52c0f3974090cd033341be2edeae6d.tar.bz2
rails-9aa2b2d7bf52c0f3974090cd033341be2edeae6d.zip
PERF: stop allocating the string "id" over and over
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods/read.rb4
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