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

Unified Diff: Source/core/events/EventPath.cpp

Issue 1136953011: Shrinking EventPath to improve memory usage and performance (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added comment. Created 5 years, 7 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 | « Source/core/events/EventPath.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/events/EventPath.cpp
diff --git a/Source/core/events/EventPath.cpp b/Source/core/events/EventPath.cpp
index 426e1ceede531f6e0bba1de46ade9bf834f4115e..0bc1a2562d85a1046e6b5f7c750f2d85609679b6 100644
--- a/Source/core/events/EventPath.cpp
+++ b/Source/core/events/EventPath.cpp
@@ -88,21 +88,21 @@ void EventPath::initialize()
calculateTreeScopePrePostOrderNumbers();
}
-void EventPath::addNodeEventContext(Node& node)
-{
- m_nodeEventContexts.append(NodeEventContext(&node, eventTargetRespectingTargetRules(node)));
-}
-
void EventPath::calculatePath()
{
ASSERT(m_node);
ASSERT(m_nodeEventContexts.isEmpty());
m_node->updateDistribution();
+ // For performance and memory usage reasons we want to store the
+ // path using as few bytes as possible and with as few allocations
+ // as possible which is why we gather the data on the stack before
+ // storing it in a perfectly sized m_nodeEventContexts Vector.
+ WillBeHeapVector<RawPtrWillBeMember<Node>, 64> nodesInPath;
Node* current = m_node;
- addNodeEventContext(*current);
+ nodesInPath.append(current);
if (!m_node->inDocument())
- return;
+ current = nullptr;
while (current) {
if (m_event && current->keepEventInNode(m_event))
break;
@@ -114,9 +114,9 @@ void EventPath::calculatePath()
ShadowRoot* containingShadowRoot = insertionPoint->containingShadowRoot();
ASSERT(containingShadowRoot);
if (!containingShadowRoot->isOldest())
- addNodeEventContext(*containingShadowRoot->olderShadowRoot());
+ nodesInPath.append(containingShadowRoot->olderShadowRoot());
}
- addNodeEventContext(*insertionPoint);
+ nodesInPath.append(insertionPoint);
}
current = insertionPoints.last();
continue;
@@ -125,13 +125,18 @@ void EventPath::calculatePath()
if (m_event && shouldStopAtShadowRoot(*m_event, *toShadowRoot(current), *m_node))
break;
current = current->shadowHost();
- addNodeEventContext(*current);
+ nodesInPath.append(current);
} else {
current = current->parentNode();
if (current)
- addNodeEventContext(*current);
+ nodesInPath.append(current);
}
}
+
+ m_nodeEventContexts.reserveCapacity(nodesInPath.size());
+ for (Node* nodeInPath : nodesInPath) {
+ m_nodeEventContexts.append(NodeEventContext(nodeInPath, eventTargetRespectingTargetRules(*nodeInPath)));
+ }
}
void EventPath::calculateTreeScopePrePostOrderNumbers()
« no previous file with comments | « Source/core/events/EventPath.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698