Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Unified Diff: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp

Issue 1611413005: Make HTMLSlotElement.distributedNodeNextTo&distributedNodePreviousTo faster (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up code Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSlotElement.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp b/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
index 774e68a45b621ddd1b6d9d2b56b8e3dd823cdcc7..1ecda59fd63da0330250352820bc4b5ac0d3c2de 100644
--- a/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLSlotElement.cpp
@@ -83,32 +83,46 @@ void HTMLSlotElement::appendAssignedNode(Node& node)
void HTMLSlotElement::appendDistributedNode(Node& node)
{
+ size_t size = m_distributedNodes.size();
m_distributedNodes.append(&node);
+ m_distributedIndices.set(&node, size);
}
void HTMLSlotElement::appendDistributedNodesFrom(const HTMLSlotElement& other)
{
+ size_t index = m_distributedNodes.size();
m_distributedNodes.appendVector(other.m_distributedNodes);
+ for (const auto& it : other.m_distributedIndices) {
+ const Node* node = it.key;
+ m_distributedIndices.set(node, index++);
+ }
}
void HTMLSlotElement::clearDistribution()
{
m_assignedNodes.clear();
m_distributedNodes.clear();
+ m_distributedIndices.clear();
}
Node* HTMLSlotElement::distributedNodeNextTo(const Node& node) const
{
- size_t index = m_distributedNodes.find(&node);
- if (index == kNotFound || index + 1 == m_distributedNodes.size())
+ const auto& it = m_distributedIndices.find(&node);
kochi 2016/02/01 06:12:15 Yeah, 'const auto&' is better than 'const auto'.
+ if (it == m_distributedIndices.end())
+ return nullptr;
+ size_t index = it->value;
+ if (index + 1 == m_distributedNodes.size())
return nullptr;
return m_distributedNodes[index + 1].get();
}
Node* HTMLSlotElement::distributedNodePreviousTo(const Node& node) const
{
- size_t index = m_distributedNodes.find(&node);
- if (index == kNotFound || index == 0)
+ const auto& it = m_distributedIndices.find(&node);
+ if (it == m_distributedIndices.end())
+ return nullptr;
+ size_t index = it->value;
+ if (index == 0)
return nullptr;
return m_distributedNodes[index - 1].get();
}
@@ -202,8 +216,11 @@ void HTMLSlotElement::updateDistributedNodesWithFallback()
DEFINE_TRACE(HTMLSlotElement)
{
+#if ENABLE(OILPAN)
visitor->trace(m_assignedNodes);
visitor->trace(m_distributedNodes);
+ visitor->trace(m_distributedIndices);
+#endif
HTMLElement::trace(visitor);
}
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSlotElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698