From ff1a1c0b4d08567e8aeaef698003b5cd96d79686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 26 Dec 2009 11:02:41 +0100 Subject: Optimize <%= render(@posts) %>. --- actionpack/lib/action_view/render/partials.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 04edb9ab44..eb035ae2dd 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -233,7 +233,17 @@ module ActionView spacer = find_template(@options[:spacer_template]).render(@view, @locals) end - result = template ? collection_with_template(template) : collection_without_template + result = if template + collection_with_template(template) + else + paths = @collection.map { |o| partial_path(o) } + + if paths.uniq.size == 1 + collection_with_template(find_template(paths.first)) + else + collection_without_template(paths) + end + end result.join(spacer).html_safe! end @@ -254,12 +264,12 @@ module ActionView segments end - def collection_without_template + def collection_without_template(collection_paths) segments, locals, as = [], @locals, @options[:as] index, template = -1, nil - @collection.each do |object| - template = find_template(partial_path(object)) + @collection.each_with_index do |object, i| + template = find_template(collection_paths[i]) locals[template.counter_name] = (index += 1) locals[template.variable_name] = object -- cgit v1.2.3