mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #33817 from schneems/schneems/dig-simple
Don’t allocate array on no args
This commit is contained in:
commit
273e73dbcd
3 changed files with 9 additions and 6 deletions
|
@ -18,9 +18,12 @@ module ActionView
|
|||
# * <tt>name</tt> - Template name
|
||||
# * <tt>finder</tt> - An instance of <tt>ActionView::LookupContext</tt>
|
||||
# * <tt>dependencies</tt> - An array of dependent views
|
||||
def digest(name:, finder:, dependencies: [])
|
||||
dependencies ||= []
|
||||
cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join(".")
|
||||
def digest(name:, finder:, dependencies: nil)
|
||||
if dependencies.nil? || dependencies.empty?
|
||||
cache_key = "#{name}.#{finder.rendered_format}"
|
||||
else
|
||||
cache_key = [ name, finder.rendered_format, dependencies ].flatten.compact.join(".")
|
||||
end
|
||||
|
||||
# this is a correctly done double-checked locking idiom
|
||||
# (Concurrent::Map's lookups have volatile semantics)
|
||||
|
@ -30,7 +33,7 @@ module ActionView
|
|||
root = tree(name, finder, partial)
|
||||
dependencies.each do |injected_dep|
|
||||
root.children << Injected.new(injected_dep, nil, nil)
|
||||
end
|
||||
end if dependencies
|
||||
finder.digest_cache[cache_key] = root.digest(finder)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,5 +19,5 @@ class RelationCacheTest < ActionView::TestCase
|
|||
assert_equal "Hello World", controller.cache_store.read("views/path/projects-#{Project.count}")
|
||||
end
|
||||
|
||||
def view_cache_dependencies; end
|
||||
def view_cache_dependencies; []; end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ module RenderTestCases
|
|||
def setup_view(paths)
|
||||
@assigns = { secret: "in the sauce" }
|
||||
@view = Class.new(ActionView::Base) do
|
||||
def view_cache_dependencies; end
|
||||
def view_cache_dependencies; []; end
|
||||
|
||||
def combined_fragment_cache_key(key)
|
||||
[ :views, key ]
|
||||
|
|
Loading…
Reference in a new issue