diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-02-12 23:25:03 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-02-12 23:25:03 +0100 |
commit | 40599d1d7468e8d13932ada859987d9d2f32cb18 (patch) | |
tree | 8619a9021bbc34a0594e974c303af17018ed6c09 /actionview/lib/action_view/renderer/partial_renderer | |
parent | 42fd563f66798ab286699520dc5f3550a6e4c575 (diff) | |
download | rails-40599d1d7468e8d13932ada859987d9d2f32cb18.tar.gz rails-40599d1d7468e8d13932ada859987d9d2f32cb18.tar.bz2 rails-40599d1d7468e8d13932ada859987d9d2f32cb18.zip |
Stop mutating return value.
`PartialRenderer.render_collection_with/without_template` returns an array
of rendered partials. Avoid dup'ing and shifting it by indexing into
the collection instead.
Diffstat (limited to 'actionview/lib/action_view/renderer/partial_renderer')
-rw-r--r-- | actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb index e13943499c..e6d57b802e 100644 --- a/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb +++ b/actionview/lib/action_view/renderer/partial_renderer/collection_caching.rb @@ -18,11 +18,12 @@ module ActionView cached_partials = collection_cache.read_multi(*keyed_collection.keys) @collection = keyed_collection.reject { |key, _| cached_partials.key?(key) }.values - rendered_partials = @collection.any? ? yield.dup : [] + rendered_partials = @collection.any? ? yield : [] + index = 0 keyed_collection.map do |cache_key, _| cached_partials.fetch(cache_key) do - rendered_partials.shift + rendered_partials[index].tap { index += 1 } end end end |