From 9aa2b2d7bf52c0f3974090cd033341be2edeae6d Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 18 Nov 2014 21:38:27 +1100 Subject: PERF: stop allocating the string "id" over and over --- activerecord/lib/active_record/attribute_methods/read.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') 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 attr_name 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 -- cgit v1.2.3