diff --git a/activerecord/lib/active_record/attribute_methods/read.rb b/activerecord/lib/active_record/attribute_methods/read.rb
index <HASH>..<HASH> 100644
--- a/activerecord/lib/active_record/attribute_methods/read.rb
+++ b/activerecord/lib/active_record/attribute_methods/read.rb
@@ -76,17 +76,17 @@ module ActiveRecord
           end
 
           def internal_attribute_access_code(attr_name, cast_code)
-            access_code = "(v=@attributes['#{attr_name}']) && #{cast_code}"
+            access_code = "(v=@attributes[attr_name]) && #{cast_code}"
 
             unless attr_name == primary_key
-              access_code.insert(0, "missing_attribute('#{attr_name}', caller) unless @attributes.has_key?('#{attr_name}'); ")
+              access_code.insert(0, "missing_attribute(attr_name, caller) unless @attributes.has_key?(attr_name); ")
             end
 
             if cache_attribute?(attr_name)
-              access_code = "@attributes_cache['#{attr_name}'] ||= (#{access_code})"
+              access_code = "@attributes_cache[attr_name] ||= (#{access_code})"
             end
 
-            access_code
+            "attr_name = '#{attr_name}'; #{access_code}"
           end
 
           def external_attribute_access_code(attr_name, cast_code)
Fewer string allocations in attribute method