Commit ff8a70bd authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make hit test on culled inline faster

This patch changes |LayoutInlineCollector| to use |IsDescendantOf()| instead of
using |HashSet<T>| to make |SelftFragmentsOf()|, which is used by hit testing
and others, faster.

I found the slowness of |LayoutInlineCollector| by CPU profiling[1] where
|HashSet<T>::insert()| consumes most of time.

So, it seems traversing fragment tree + LayoutObject::IsDescendnatOf()| is
faster than two times of traversing fragment tree + |HashSet<T>::insert()|.


[1] https://bit.ly/2pXQbcE

Bug: 1008523
Change-Id: I825197f2b85fd2ef573e8ff159ddf966489361be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847602
Auto-Submit: Yoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704102}
parent ff931767
......@@ -122,9 +122,8 @@ class LayoutInlineCollector final : public NGPhysicalFragmentCollectorBase {
STACK_ALLOCATED();
public:
explicit LayoutInlineCollector(const LayoutInline& container) {
CollectInclusiveDescendants(container);
}
explicit LayoutInlineCollector(const LayoutInline& container)
: container_(container) {}
Vector<Result> CollectFrom(const NGPhysicalFragment& fragment) final {
return CollectExclusivelyFrom(fragment);
......@@ -133,30 +132,14 @@ class LayoutInlineCollector final : public NGPhysicalFragmentCollectorBase {
private:
void Visit() final {
if (!GetFragment().IsLineBox() &&
inclusive_descendants_.Contains(GetFragment().GetLayoutObject())) {
GetFragment().GetLayoutObject()->IsDescendantOf(&container_)) {
Emit();
return;
}
VisitChildren();
}
void CollectInclusiveDescendants(const LayoutInline& container) {
inclusive_descendants_.insert(&container);
for (const LayoutObject* node = container.FirstChild(); node;
node = node->NextSibling()) {
if (node->IsFloatingOrOutOfFlowPositioned())
continue;
if (node->IsBox() || node->IsText()) {
inclusive_descendants_.insert(node);
continue;
}
if (!node->IsLayoutInline())
continue;
CollectInclusiveDescendants(ToLayoutInline(*node));
}
}
HashSet<const LayoutObject*> inclusive_descendants_;
const LayoutInline& container_;
DISALLOW_COPY_AND_ASSIGN(LayoutInlineCollector);
};
......
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