Permalink
Browse files

Roflscaling!

Don't prefix the name with attribute_. Avoids a string allocation on
read_attribute, which is a bit faster.
  • Loading branch information...
1 parent 9ead413 commit f6b5046305d43c5f64bcb6fed0e44f7bca99a603 @jonleighton jonleighton committed Dec 1, 2011
@@ -31,9 +31,9 @@ def define_method_attribute(attr_name)
if attr_name == primary_key && attr_name != 'id'
generated_attribute_methods.send(:alias_method, :id, primary_key)
generated_attribute_methods.module_eval <<-CODE, __FILE__, __LINE__
- def self.attribute_id(v, attributes, attributes_cache, attr_name)
+ def self.id(v, attributes, attributes_cache, attr_name)
attr_name = '#{primary_key}'
- send(:'attribute_#{attr_name}', attributes[attr_name], attributes, attributes_cache, attr_name)
+ send(attr_name, attributes[attr_name], attributes, attributes_cache, attr_name)
end
CODE
end
@@ -30,11 +30,9 @@ def cache_attribute?(attr_name)
end
def undefine_attribute_methods
- if base_class == self
- generated_attribute_methods.module_eval do
- public_methods(false).each do |m|
- singleton_class.send(:undef_method, m) if m.to_s =~ /^attribute_/
- end
+ if base_class == self && attribute_methods_generated?
+ column_names.each do |name|
+ generated_attribute_methods.singleton_class.send(:undef_method, name)
end
end
@@ -67,7 +65,7 @@ def __temp__
def __temp__(v, attributes, attributes_cache, attr_name)
#{external}
end
- alias_method 'attribute_#{attr_name}', :__temp__
+ alias_method '#{attr_name}', :__temp__
jonleighton
jonleighton Dec 1, 2011 Member

It's inside a heredoc.

joshbuddy
joshbuddy Dec 1, 2011

Among the things that aren't obvious looking at a diff.

undef_method :__temp__
STR
end
@@ -110,12 +108,11 @@ def attribute_cast_code(attr_name)
# "2004-12-12" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name)
attr_name = attr_name.to_s
- accessor = "attribute_#{attr_name}"
methods = self.class.generated_attribute_methods
- if methods.respond_to?(accessor)
+ if methods.respond_to?(attr_name)
if @attributes.has_key?(attr_name) || attr_name == 'id'
- methods.send(accessor, @attributes[attr_name], @attributes, @attributes_cache, attr_name)
+ methods.send(attr_name, @attributes[attr_name], @attributes, @attributes_cache, attr_name)
end
elsif !self.class.attribute_methods_generated?
# If we haven't generated the caster methods yet, do that and

4 comments on commit f6b5046

@jeremy
Owner
jeremy commented on f6b5046 Dec 2, 2011

Causing an issue with Sam's tests @ http://intertwingly.net/projects/AWDwR4/checkdepot-193/

@tenderlove
Owner
@jonleighton
Member

Judging by the erorrs ("undefined method status_code' for classActionDispatch::ShowExceptions'") I think this might be to do with the exceptions merge.

Looks like the CI has stopped building, will try to ping josh about that.

@josevalim
Member
Please sign in to comment.