[go: up one dir, main page]

Allocate vector of NGOutOfFlowPositionedDescendant in NGPhysicalContainerFragment only unless empty

This patch changes |NGPhysicalContainerFragment| to allocate vector of
|NGOutOfFlowPositionedDescendant| only if it is not empty for reducing memory
usage.

TBR=yosin@chromium.org
Bug: 962108

Change-Id: If807348f4f9842e138a7fe3ae3491094e510ea73
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1661320
Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/branch-heads/3809@{#337}
Cr-Branched-From: d82dec1a818f378c464ba307ddd9c92133eac355-refs/heads/master@{#665002}
diff --git a/third_party/blink/renderer/core/layout/layout_object.cc b/third_party/blink/renderer/core/layout/layout_object.cc
index 8c78317..b8f87d5 100644
--- a/third_party/blink/renderer/core/layout/layout_object.cc
+++ b/third_party/blink/renderer/core/layout/layout_object.cc
@@ -925,9 +925,8 @@
     // parent. Therefore, we must mark parent chain for layout.
     if (layout_box->GetCachedLayoutResult() &&
         layout_box->GetCachedLayoutResult()
-                ->PhysicalFragment()
-                .OutOfFlowPositionedDescendants()
-                .size() > 0)
+            ->PhysicalFragment()
+            .HasOutOfFlowPositionedDescendants())
       return false;
   }
 
diff --git a/third_party/blink/renderer/core/layout/ng/inline/ng_inline_node.cc b/third_party/blink/renderer/core/layout/ng/inline/ng_inline_node.cc
index 0045de8..bad264f 100644
--- a/third_party/blink/renderer/core/layout/ng/inline/ng_inline_node.cc
+++ b/third_party/blink/renderer/core/layout/ng/inline/ng_inline_node.cc
@@ -995,9 +995,8 @@
     return nullptr;
 
   // Propagating OOF needs re-layout.
-  if (!cached_layout_result->PhysicalFragment()
-           .OutOfFlowPositionedDescendants()
-           .IsEmpty())
+  if (cached_layout_result->PhysicalFragment()
+          .HasOutOfFlowPositionedDescendants())
     return nullptr;
 
   // Cached fragments are not for intermediate layout.
diff --git a/third_party/blink/renderer/core/layout/ng/inline/ng_line_truncator.cc b/third_party/blink/renderer/core/layout/ng/inline/ng_line_truncator.cc
index caf78a0..747f3f13 100644
--- a/third_party/blink/renderer/core/layout/ng/inline/ng_line_truncator.cc
+++ b/third_party/blink/renderer/core/layout/ng/inline/ng_line_truncator.cc
@@ -99,9 +99,7 @@
   const NGPhysicalFragment* fragment = nullptr;
   if (const NGLayoutResult* layout_result = child->layout_result.get()) {
     // Need to propagate OOF descendants in this inline-block child.
-    if (!layout_result->PhysicalFragment()
-             .OutOfFlowPositionedDescendants()
-             .IsEmpty())
+    if (layout_result->PhysicalFragment().HasOutOfFlowPositionedDescendants())
       return;
     fragment = &layout_result->PhysicalFragment();
   } else {
diff --git a/third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.cc b/third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.cc
index 0ac7582..0868185 100644
--- a/third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.cc
+++ b/third_party/blink/renderer/core/layout/ng/inline/ng_physical_line_box_fragment.cc
@@ -66,7 +66,7 @@
   base_direction_ = static_cast<unsigned>(builder->base_direction_);
   has_hanging_ = builder->hang_inline_size_ != 0;
   has_propagated_descendants_ = has_floating_descendants_ ||
-                                !oof_positioned_descendants_.IsEmpty() ||
+                                HasOutOfFlowPositionedDescendants() ||
                                 builder->unpositioned_list_marker_;
 }
 
diff --git a/third_party/blink/renderer/core/layout/ng/ng_container_fragment_builder.cc b/third_party/blink/renderer/core/layout/ng/ng_container_fragment_builder.cc
index 8e45280..43a50cd1c 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_container_fragment_builder.cc
+++ b/third_party/blink/renderer/core/layout/ng/ng_container_fragment_builder.cc
@@ -19,8 +19,9 @@
   // 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();
-  if (!out_of_flow_descendants.IsEmpty()) {
+  if (child.HasOutOfFlowPositionedDescendants()) {
+    const auto& out_of_flow_descendants =
+        child.OutOfFlowPositionedDescendants();
     LogicalOffset top_left_offset;
     PhysicalSize child_size = child.Size();
     switch (GetWritingMode()) {
diff --git a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.cc b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.cc
index f46de53..fcca557 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.cc
+++ b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.cc
@@ -17,6 +17,7 @@
 namespace {
 
 struct SameSizeAsNGPhysicalContainerFragment : NGPhysicalFragment {
+<<<<<<< HEAD   (4386eb Move break_token_ to NGPhysicalContainerFragment from NGPhys)
 <<<<<<< HEAD   (d91d4f Allocate memory for borders and padding members of NGPhysica)
   Vector<NGOutOfFlowPositionedDescendant> oof_positioned_descendants_;
 =======
@@ -24,6 +25,10 @@
   std::unique_ptr<Vector<NGOutOfFlowPositionedDescendant>>
       oof_positioned_descendants_;
 >>>>>>> CHANGE (3ad1c0 Move break_token_ to NGPhysicalContainerFragment from NGPhys)
+=======
+  std::unique_ptr<Vector<NGOutOfFlowPositionedDescendant>>
+      oof_positioned_descendants_;
+>>>>>>> CHANGE (763c67 Allocate vector of NGOutOfFlowPositionedDescendant in NGPhys)
   void* pointer;
   wtf_size_t size;
 };
@@ -43,7 +48,10 @@
     : NGPhysicalFragment(builder, type, sub_type),
       break_token_(std::move(builder->break_token_)),
       oof_positioned_descendants_(
-          std::move(builder->oof_positioned_descendants_)),
+          builder->oof_positioned_descendants_.IsEmpty()
+              ? nullptr
+              : new Vector<NGOutOfFlowPositionedDescendant>(
+                    std::move(builder->oof_positioned_descendants_))),
       buffer_(buffer),
       num_children_(builder->children_.size()) {
   has_floating_descendants_ = builder->has_floating_descendants_;
diff --git a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
index 3d24e51..6bfe786 100644
--- a/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
+++ b/third_party/blink/renderer/core/layout/ng/ng_physical_container_fragment.h
@@ -5,6 +5,7 @@
 #ifndef NGPhysicalContainerFragment_h
 #define NGPhysicalContainerFragment_h
 
+#include "base/containers/span.h"
 #include "third_party/blink/renderer/core/core_export.h"
 #include "third_party/blink/renderer/core/layout/geometry/physical_rect.h"
 #include "third_party/blink/renderer/core/layout/ng/ng_break_token.h"
@@ -133,9 +134,18 @@
     return depends_on_percentage_block_size_;
   }
 
-  const Vector<NGOutOfFlowPositionedDescendant>&
-  OutOfFlowPositionedDescendants() const {
-    return oof_positioned_descendants_;
+  bool HasOutOfFlowPositionedDescendants() const {
+    DCHECK(!oof_positioned_descendants_ ||
+           !oof_positioned_descendants_->IsEmpty());
+    return oof_positioned_descendants_.get();
+  }
+
+  base::span<NGOutOfFlowPositionedDescendant> OutOfFlowPositionedDescendants()
+      const {
+    if (!HasOutOfFlowPositionedDescendants())
+      return base::span<NGOutOfFlowPositionedDescendant>();
+    return {oof_positioned_descendants_->data(),
+            oof_positioned_descendants_->size()};
   }
 
  protected:
@@ -160,6 +170,7 @@
 
   static bool DependsOnPercentageBlockSize(const NGContainerFragmentBuilder&);
 
+<<<<<<< HEAD   (4386eb Move break_token_ to NGPhysicalContainerFragment from NGPhys)
 <<<<<<< HEAD   (d91d4f Allocate memory for borders and padding members of NGPhysica)
   Vector<NGOutOfFlowPositionedDescendant> oof_positioned_descendants_;
 =======
@@ -167,6 +178,10 @@
   const std::unique_ptr<Vector<NGOutOfFlowPositionedDescendant>>
       oof_positioned_descendants_;
 >>>>>>> CHANGE (3ad1c0 Move break_token_ to NGPhysicalContainerFragment from NGPhys)
+=======
+  const std::unique_ptr<Vector<NGOutOfFlowPositionedDescendant>>
+      oof_positioned_descendants_;
+>>>>>>> CHANGE (763c67 Allocate vector of NGOutOfFlowPositionedDescendant in NGPhys)
 
   // Because flexible arrays need to be the last member in a class, the actual
   // storage is in the subclass and we just keep a pointer to it here.