Commit 9125ca62 authored by Hayato Ito's avatar Hayato Ito Committed by Commit Bot

Introduce flat_tree_children_ in preparation for reducing the number of will-be-reattached nodes

This CL is just a refactoring so that we can lazyReattach nodes in once place.

In follow-up CLs, I'll reduce the number of LazyReattached nodes, unifying this with
dynamic programming code as HTMLSlotElement::LazyReattachDistributedNodesIfNeeded does.

Bug: 776656
Change-Id: I17813a39c57cc5bbea5e8c529805123ccabd4c69
Reviewed-on: https://chromium-review.googlesource.com/984917Reviewed-by: default avatarRakina Zata Amni <rakina@chromium.org>
Reviewed-by: default avatarTakayoshi Kochi <kochi@chromium.org>
Commit-Queue: Hayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546771}
parent 549a2a4d
...@@ -237,8 +237,6 @@ void SlotAssignment::RecalcAssignmentNg() { ...@@ -237,8 +237,6 @@ void SlotAssignment::RecalcAssignmentNg() {
for (Node& child : NodeTraversal::ChildrenOf(owner_->host())) { for (Node& child : NodeTraversal::ChildrenOf(owner_->host())) {
if (!child.IsSlotable()) if (!child.IsSlotable())
continue; continue;
// TODO(hayato): Avoid unconditional LazyReattach
child.LazyReattachIfAttached();
HTMLSlotElement* slot = nullptr; HTMLSlotElement* slot = nullptr;
if (!is_user_agent) { if (!is_user_agent) {
...@@ -253,11 +251,7 @@ void SlotAssignment::RecalcAssignmentNg() { ...@@ -253,11 +251,7 @@ void SlotAssignment::RecalcAssignmentNg() {
if (slot) if (slot)
slot->AppendAssignedNode(child); slot->AppendAssignedNode(child);
} else
// TODO(hayato): Avoid unconditional LazyReattach
for (Member<HTMLSlotElement> slot : Slots()) {
for (Node& child : NodeTraversal::ChildrenOf(*slot))
child.LazyReattachIfAttached(); child.LazyReattachIfAttached();
} }
...@@ -266,6 +260,9 @@ void SlotAssignment::RecalcAssignmentNg() { ...@@ -266,6 +260,9 @@ void SlotAssignment::RecalcAssignmentNg() {
.GetSlotAssignmentEngine() .GetSlotAssignmentEngine()
.RemoveShadowRootNeedingRecalc(*owner_); .RemoveShadowRootNeedingRecalc(*owner_);
} }
for (auto& slot : Slots())
slot->RecalcFlatTreeChildren();
} }
void SlotAssignment::RecalcAssignment() { void SlotAssignment::RecalcAssignment() {
......
...@@ -230,13 +230,33 @@ void HTMLSlotElement::AppendDistributedNodesFrom(const HTMLSlotElement& other) { ...@@ -230,13 +230,33 @@ void HTMLSlotElement::AppendDistributedNodesFrom(const HTMLSlotElement& other) {
void HTMLSlotElement::ClearAssignedNodes() { void HTMLSlotElement::ClearAssignedNodes() {
DCHECK(RuntimeEnabledFeatures::IncrementalShadowDOMEnabled()); DCHECK(RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
// TODO(hayato): Avoid uncondional LazyReattach
for (const auto& node : assigned_nodes_)
node->LazyReattachIfAttached();
assigned_nodes_.clear(); assigned_nodes_.clear();
} }
void HTMLSlotElement::RecalcFlatTreeChildren() {
DCHECK(RuntimeEnabledFeatures::IncrementalShadowDOMEnabled());
DCHECK(SupportsAssignment());
HeapVector<Member<Node>> old_flat_tree_children;
old_flat_tree_children.swap(flat_tree_children_);
if (assigned_nodes_.IsEmpty()) {
// Use children as fallback
for (auto& child : NodeTraversal::ChildrenOf(*this))
flat_tree_children_.push_back(child);
} else {
flat_tree_children_ = assigned_nodes_;
}
// Tentative naive version.
// TODO(hayato): Optimize this, as we do in
// |LazyReattachDistributedNodesIfNeeded|.
for (auto& node : old_flat_tree_children)
node->LazyReattachIfAttached();
for (auto& node : flat_tree_children_)
node->LazyReattachIfAttached();
}
void HTMLSlotElement::ClearDistribution() { void HTMLSlotElement::ClearDistribution() {
assigned_nodes_.clear(); assigned_nodes_.clear();
distributed_nodes_.clear(); distributed_nodes_.clear();
...@@ -642,6 +662,7 @@ int HTMLSlotElement::tabIndex() const { ...@@ -642,6 +662,7 @@ int HTMLSlotElement::tabIndex() const {
void HTMLSlotElement::Trace(blink::Visitor* visitor) { void HTMLSlotElement::Trace(blink::Visitor* visitor) {
visitor->Trace(assigned_nodes_); visitor->Trace(assigned_nodes_);
visitor->Trace(flat_tree_children_);
visitor->Trace(distributed_nodes_); visitor->Trace(distributed_nodes_);
visitor->Trace(old_distributed_nodes_); visitor->Trace(old_distributed_nodes_);
visitor->Trace(distributed_indices_); visitor->Trace(distributed_indices_);
......
...@@ -124,6 +124,7 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement { ...@@ -124,6 +124,7 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement {
// For Incremental Shadow DOM // For Incremental Shadow DOM
void ClearAssignedNodes(); void ClearAssignedNodes();
void RecalcFlatTreeChildren();
static AtomicString NormalizeSlotName(const AtomicString&); static AtomicString NormalizeSlotName(const AtomicString&);
...@@ -159,6 +160,9 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement { ...@@ -159,6 +160,9 @@ class CORE_EXPORT HTMLSlotElement final : public HTMLElement {
HeapVector<Member<Node>> assigned_nodes_; HeapVector<Member<Node>> assigned_nodes_;
// For IncrementalShadowDOM
HeapVector<Member<Node>> flat_tree_children_;
// For Non-IncrmentalShadowDOM. IncremntalShadowDOM never use these members. // For Non-IncrmentalShadowDOM. IncremntalShadowDOM never use these members.
HeapVector<Member<Node>> distributed_nodes_; HeapVector<Member<Node>> distributed_nodes_;
HeapVector<Member<Node>> old_distributed_nodes_; HeapVector<Member<Node>> old_distributed_nodes_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment