Skip to content

Commit

Permalink
[layoutng] Add some microoptimizations
Browse files Browse the repository at this point in the history
I'm trying to figure out why NGLink made things slower, and
while I don't expect these changes to make the difference,
they shouldn't hurt.

R=eae@chromium.org

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I7dd6f5130f3ebcd07dfb44d0af801ab28516bcc9
Reviewed-on: https://chromium-review.googlesource.com/1207650
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588989}
  • Loading branch information
cbiesinger authored and Commit Bot committed Sep 5, 2018
1 parent bb26055 commit 0c48f75
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ NGInlineLayoutStateStack::BoxData::CreateBoxFragment(
for (unsigned i = fragment_start; i < fragment_end; i++) {
NGLineBoxFragmentBuilder::Child& child = (*line_box)[i];
if (child.layout_result) {
box.AddChild(std::move(child.layout_result), child.offset - offset);
box.AddChild(*child.layout_result, child.offset - offset);
child.layout_result.reset();
} else if (child.fragment) {
box.AddChild(std::move(child.fragment), child.offset - offset);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ void NGLineBoxFragmentBuilder::AddChildren(ChildList& children) {
for (auto& child : children) {
if (child.layout_result) {
DCHECK(!child.fragment);
AddChild(std::move(child.layout_result), child.offset);
DCHECK(!child.layout_result);
AddChild(*child.layout_result, child.offset);
child.layout_result.reset();
} else if (child.fragment) {
AddChild(std::move(child.fragment), child.offset);
DCHECK(!child.fragment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ bool NGUnpositionedListMarker::AddToBox(
marker_offset.block_offset);

DCHECK(container_builder);
container_builder->AddChild(std::move(marker_layout_result), marker_offset);
container_builder->AddChild(*marker_layout_result, marker_offset);

return true;
}
Expand All @@ -140,7 +140,7 @@ LayoutUnit NGUnpositionedListMarker::AddToBoxWithoutLineBoxes(
NGLogicalOffset offset(InlineOffset(marker_size.inline_size), LayoutUnit());

DCHECK(container_builder);
container_builder->AddChild(std::move(marker_layout_result), offset);
container_builder->AddChild(*marker_layout_result, offset);

return marker_size.block_size;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ bool NGBlockLayoutAlgorithm::HandleNewFormattingContext(

PositionOrPropagateListMarker(*layout_result, &logical_offset);

container_builder_.AddChild(layout_result, logical_offset);
container_builder_.AddChild(*layout_result, logical_offset);
container_builder_.PropagateBreak(layout_result);

// The margins we store will be used by e.g. getComputedStyle().
Expand Down Expand Up @@ -1277,7 +1277,7 @@ bool NGBlockLayoutAlgorithm::HandleInflow(
layout_result->AdjoiningFloatTypes());
}

container_builder_.AddChild(layout_result, logical_offset);
container_builder_.AddChild(*layout_result, logical_offset);
if (child.IsBlock())
container_builder_.PropagateBreak(layout_result);

Expand Down Expand Up @@ -2071,7 +2071,8 @@ void NGBlockLayoutAlgorithm::AddPositionedFloats(
child_fragment, positioned_float.bfc_offset, bfc_offset,
container_builder_.Size().inline_size, ConstraintSpace().Direction());

container_builder_.AddChild(positioned_float.layout_result, logical_offset);
container_builder_.AddChild(*positioned_float.layout_result,
logical_offset);
container_builder_.PropagateBreak(positioned_float.layout_result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ scoped_refptr<NGLayoutResult> NGColumnLayoutAlgorithm::Layout() {
ToNGPhysicalBoxFragment(result->PhysicalFragment().get()));

NGLogicalOffset logical_offset(column_inline_offset, column_block_offset);
container_builder_.AddChild(result, logical_offset);
container_builder_.AddChild(*result, logical_offset);

LayoutUnit space_shortage = result->MinimalSpaceShortage();
if (space_shortage > LayoutUnit()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ NGContainerFragmentBuilder::SetUnpositionedListMarker(
}

NGContainerFragmentBuilder& NGContainerFragmentBuilder::AddChild(
scoped_refptr<NGLayoutResult> child,
const NGLayoutResult& child,
const NGLogicalOffset& child_offset) {
// Collect the child's out of flow descendants.
// child_offset is offset of inline_start/block_start vertex.
// Candidates need offset of top/left vertex.
const auto& out_of_flow_descendants = child->OutOfFlowPositionedDescendants();
const auto& out_of_flow_descendants = child.OutOfFlowPositionedDescendants();
if (!out_of_flow_descendants.IsEmpty()) {
NGLogicalOffset top_left_offset;
NGPhysicalSize child_size = child->PhysicalFragment()->Size();
NGPhysicalSize child_size = child.PhysicalFragment()->Size();
switch (GetWritingMode()) {
case WritingMode::kHorizontalTb:
top_left_offset =
Expand Down Expand Up @@ -91,7 +91,7 @@ NGContainerFragmentBuilder& NGContainerFragmentBuilder::AddChild(
}
}

return AddChild(child->PhysicalFragment(), child_offset);
return AddChild(child.PhysicalFragment(), child_offset);
}

NGContainerFragmentBuilder& NGContainerFragmentBuilder::AddChild(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CORE_EXPORT NGContainerFragmentBuilder : public NGBaseFragmentBuilder {
NGContainerFragmentBuilder& SetUnpositionedListMarker(
const NGUnpositionedListMarker&);

virtual NGContainerFragmentBuilder& AddChild(scoped_refptr<NGLayoutResult>,
virtual NGContainerFragmentBuilder& AddChild(const NGLayoutResult&,
const NGLogicalOffset&);

// This version of AddChild will not propagate floats/out_of_flow.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ scoped_refptr<NGLayoutResult> NGFlexLayoutAlgorithm::Layout() {
for (size_t i = 0; i < line->line_items.size(); ++i) {
FlexItem& flex_item = line->line_items[i];
container_builder_.AddChild(
flex_item.layout_result,
*flex_item.layout_result,
{flex_item.desired_location.X(), flex_item.desired_location.Y()});
}

Expand Down
8 changes: 6 additions & 2 deletions third_party/blink/renderer/core/layout/ng/ng_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class CORE_EXPORT NGLink {
NGLink() = default;
NGLink(scoped_refptr<const NGPhysicalFragment> fragment,
NGPhysicalOffset offset)
: fragment_(fragment), offset_(offset) {}
: fragment_(std::move(fragment)), offset_(offset) {}
NGLink(NGLink&& o) noexcept
: fragment_(std::move(o.fragment_)), offset_(o.offset_) {}
~NGLink() = default;

// Returns the offset relative to the parent fragment's content-box.
Expand All @@ -44,10 +46,12 @@ class CORE_EXPORT NGLink {
friend class NGFragmentBuilder;
friend class NGLineBoxFragmentBuilder;
friend class NGLayoutResult;

DISALLOW_COPY_AND_ASSIGN(NGLink);
};

} // namespace blink

WTF_ALLOW_MOVE_AND_INIT_WITH_MEM_FUNCTIONS(blink::NGLink);
WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(blink::NGLink);

#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_NG_NG_LINK_H_
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void NGOutOfFlowLayoutPart::Run(LayoutBox* only_layout) {
NGLogicalOffset offset;
scoped_refptr<NGLayoutResult> result =
LayoutDescendant(candidate, &offset);
container_builder_->AddChild(std::move(result), offset);
container_builder_->AddChild(*result, offset);
if (candidate.node.GetLayoutBox() != only_layout)
candidate.node.UseOldOutOfFlowPositioning();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ scoped_refptr<NGLayoutResult> NGPageLayoutAlgorithm::Layout() {
scoped_refptr<const NGPhysicalBoxFragment> page(
ToNGPhysicalBoxFragment(result->PhysicalFragment().get()));

container_builder_.AddChild(result, page_offset);
container_builder_.AddChild(*result, page_offset);

NGBoxFragment logical_fragment(writing_mode, ConstraintSpace().Direction(),
*page);
Expand Down

0 comments on commit 0c48f75

Please sign in to comment.