diff options
author | José Valim <jose.valim@gmail.com> | 2011-07-28 10:01:55 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2011-08-13 16:22:21 -0700 |
commit | 554ea3c37b21be56f7f82c1179f2553dc445dc37 (patch) | |
tree | f5de426d6dcc0d8e6964aa7f0c84f7319b5ee43d /actionpack/lib/action_view | |
parent | 91ca214ca0aa431f3cbe90d660c22129b3584bc7 (diff) | |
download | rails-554ea3c37b21be56f7f82c1179f2553dc445dc37.tar.gz rails-554ea3c37b21be56f7f82c1179f2553dc445dc37.tar.bz2 rails-554ea3c37b21be56f7f82c1179f2553dc445dc37.zip |
Move the cache to a nested hash which performs better than a hash with array as keys.
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/renderer/partial_renderer.rb | 28 |
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 |