Created
September 7, 2014 15:44
-
-
Save brainopia/eac2ba731015fdbc9382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rails 3.X patch to remove extra allocations on field access | |
module ActiveRecord::AttributeMethods::Read::ClassMethods | |
def internal_attribute_access_code(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); ") | |
end | |
if cache_attribute?(attr_name) | |
access_code = "@attributes_cache[attr_name] ||= (#{access_code})" | |
end | |
# this line has been changed | |
"attr_name = @@attr_#{attr_name} ||= '#{attr_name}'; #{access_code}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment