aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-07-28 10:01:55 +0200
committerJosé Valim <jose.valim@gmail.com>2011-07-28 10:01:55 +0200
commitd5eeacc95f116d438210469b6be573913f562b08 (patch)
tree1e06c7dd1adff1f11fe9f9e826d2678365e40e59 /actionpack/lib
parentdee81155395658880ea125426036425250849298 (diff)
downloadrails-d5eeacc95f116d438210469b6be573913f562b08.tar.gz
rails-d5eeacc95f116d438210469b6be573913f562b08.tar.bz2
rails-d5eeacc95f116d438210469b6be573913f562b08.zip
Move the cache to a nested hash which performs better than a hash with array as keys.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/renderer/partial_renderer.rb28
1 files changed, 17 insertions, 11 deletions
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb
index fc8a6b3107..f67388b8cf 100644
--- a/actionpack/lib/action_view/renderer/partial_renderer.rb
+++ b/actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -206,6 +206,14 @@ module ActionView
# <%- end -%>
# <% end %>
class PartialRenderer < AbstractRenderer #:nodoc:
+ PARTIAL_NAMES = Hash.new { |h,k| h[k] = {} }
+
+ def initialize(*)
+ super
+ @context_prefix = @lookup_context.prefixes.first
+ @partial_names = PARTIAL_NAMES[@context_prefix]
+ end
+
def render(context, options, block)
setup(context, options, block)
@@ -284,6 +292,7 @@ module ActionView
else
paths.map! { |path| retrieve_variable(path).unshift(path) }
end
+
if String === partial && @variable.to_s !~ /^[a-z_][a-zA-Z_0-9]*$/
raise ArgumentError.new("The partial name (#{partial}) is not a valid Ruby identifier; " +
"make sure your partial name starts with a letter or underscore, " +
@@ -352,21 +361,18 @@ module ActionView
segments
end
- PARTIAL_PATHS = {}
-
def partial_path(object = @object)
object = object.to_model if object.respond_to?(:to_model)
path = if object.respond_to?(:to_path)
- object.to_path
- else
- ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead."
- object.class.model_name.partial_path
- end
-
- prefix = @lookup_context.prefixes.first
- PARTIAL_PATHS[ [path, prefix] ] ||= path.dup.tap do |object_path|
- merge_prefix_into_object_path(prefix, object_path)
+ object.to_path
+ else
+ ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_path directly instead."
+ object.class.model_name.partial_path
+ end
+
+ @partial_names[path] ||= path.dup.tap do |object_path|
+ merge_prefix_into_object_path(@context_prefix, object_path)
end
end