Permalink
Browse files

Avoid logging code if logger is nil. Closes #2881.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3056 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent eb1dd6a commit ede505592cfab0212e53ca8ad1c38026a7b5d042 @jeremy jeremy committed Nov 16, 2005
Showing with 16 additions and 5 deletions.
  1. +1 −1 actionpack/CHANGELOG
  2. +15 −4 actionpack/lib/action_view/partials.rb
View
@@ -1,6 +1,6 @@
*SVN*
-* Use Set instead of Array to speed up prototype helper include? calls. #2880 [Stefan Kaes]
+* Performance tweaks: use Set instead of Array to speed up prototype helper include? calls. Avoid logging code if logger is nil. #2880, #2881 [Stefan Kaes]
* MemCache store may be given multiple addresses. #2869 [Ryan Carver <ryan@fivesevensix.com>]
@@ -54,7 +54,11 @@ def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns =
add_counter_to_local_assigns!(partial_name, local_assigns)
add_object_to_local_assigns!(partial_name, local_assigns, object)
- ActionController::Base.benchmark("Rendered #{path}/_#{partial_name}", Logger::DEBUG, false) do
+ if logger
+ ActionController::Base.benchmark("Rendered #{path}/_#{partial_name}", Logger::DEBUG, false) do
+ render("#{path}/_#{partial_name}", local_assigns)
+ end
+ else
render("#{path}/_#{partial_name}", local_assigns)
end
end
@@ -111,10 +115,17 @@ def add_counter_to_local_assigns!(partial_name, local_assigns)
counter_name = partial_counter_name(partial_name)
local_assigns[counter_name] = 1 unless local_assigns.has_key?(counter_name)
end
-
+
def add_object_to_local_assigns!(partial_name, local_assigns, object)
- local_assigns[partial_name.intern] ||= object.is_a?(ActionView::Base::ObjectWrapper) ? object.value : object
- local_assigns[partial_name.intern] ||= controller.instance_variable_get("@#{partial_name}")
+ local_assigns[partial_name.intern] ||= unwrap_object(object) || controller.instance_variable_get("@#{partial_name}")
+ end
+
+ def unwrap_object(object)
+ if object.is_a?(ActionView::Base::ObjectWrapper)
+ object.value
+ else
+ object
+ end
end
end
end

0 comments on commit ede5055

Please sign in to comment.