Permalink
Browse files

Fewer string allocations in attribute method

  • Loading branch information...
jonleighton committed Dec 1, 2011
1 parent f6b5046 commit 6bff6439b1960891669485dc978af68dab15af27
Showing with 4 additions and 4 deletions.
  1. +4 −4 activerecord/lib/active_record/attribute_methods/read.rb
@@ -76,17 +76,17 @@ def cacheable_column?(column)
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)

0 comments on commit 6bff643

Please sign in to comment.