diff options
author | Rick Olson <technoweenie@gmail.com> | 2008-02-14 07:24:09 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2008-02-14 07:24:09 +0000 |
commit | 8a2266c02063c1111c666c71ced7822f095ed56c (patch) | |
tree | 1420ac25830d4e1f8da1c1035369b703617f4ed0 /activerecord/lib/active_record/associations/association_collection.rb | |
parent | dfa786631bb8476c8cae555ad8de5e83811dfe9d (diff) | |
download | rails-8a2266c02063c1111c666c71ced7822f095ed56c.tar.gz rails-8a2266c02063c1111c666c71ced7822f095ed56c.tar.bz2 rails-8a2266c02063c1111c666c71ced7822f095ed56c.zip |
Improve associations performance by avoiding named block arguments. Closes #11109
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8865 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations/association_collection.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 79cd227c0c..d400a5c772 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -43,8 +43,8 @@ module ActiveRecord end # Calculate sum using SQL, not Enumerable - def sum(*args, &block) - calculate(:sum, *args, &block) + def sum(*args) + calculate(:sum, *args) { |*block_args| yield(*block_args) if block_given? } end # Remove +records+ from this association. Does not destroy +records+. @@ -121,9 +121,9 @@ module ActiveRecord size.zero? end - def any?(&block) + def any? if block_given? - method_missing(:any?, &block) + method_missing(:any?) { |*block_args| yield(*block_args) if block_given? } else !empty? end @@ -157,11 +157,13 @@ module ActiveRecord protected - def method_missing(method, *args, &block) + def method_missing(method, *args) if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) - super + super { |*block_args| yield(*block_args) if block_given? } else - @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.send(method, *args, &block) } + @reflection.klass.send(:with_scope, construct_scope) { + @reflection.klass.send(method, *args) { |*block_args| yield(*block_args) if block_given? } + } end end @@ -187,15 +189,15 @@ module ActiveRecord private - def create_record(attrs, &block) + def create_record(attrs) ensure_owner_is_not_new record = @reflection.klass.send(:with_scope, :create => construct_scope[:create]) { @reflection.klass.new(attrs) } - add_record_to_target_with_callbacks(record, &block) + add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } end - def build_record(attrs, &block) + def build_record(attrs) record = @reflection.klass.new(attrs) - add_record_to_target_with_callbacks(record, &block) + add_record_to_target_with_callbacks(record) { |*block_args| yield(*block_args) if block_given? } end def add_record_to_target_with_callbacks(record) |