From 560517689c3cf18736bcfe39c34985ddd001a2ca Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 16 Jul 2013 11:54:46 -0700 Subject: cache the scope chain on the stack and eliminate `i` --- .../associations/join_dependency/join_association.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index 06b70c050e..75e4ed09a2 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -69,9 +69,11 @@ module ActiveRecord foreign_table = parent_table foreign_klass = parent.base_klass + scope_chain_iter = reflection.scope_chain.reverse_each + # The chain starts with the target table, but we want to end with it here (makes # more sense in this context), so we reverse - chain.reverse.each_with_index do |reflection, i| + chain.reverse_each do |reflection| table = tables.shift case reflection.source_macro @@ -97,7 +99,7 @@ module ActiveRecord constraint = build_constraint(reflection, table, key, foreign_table, foreign_key) - scope_chain_items = scope_chain[i].map do |item| + scope_chain_items = scope_chain_iter.next.map do |item| if item.is_a?(Relation) item else @@ -170,11 +172,6 @@ module ActiveRecord def aliased_table_name table.table_alias || table.name end - - def scope_chain - @scope_chain ||= reflection.scope_chain.reverse - end - end end end -- cgit v1.2.3