Commit 440a0650 authored by Christian Biesinger's avatar Christian Biesinger Committed by Commit Bot

[layoutng] Replace some uses of clear() with resize(0)

clear() also frees the backing store of the vector. This patch
replaces it with resize(0), which doesn't do that, in cases
where that seems unnecessary/undesirable.

R=eae@chromium.org

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I2e4360756d2c1a4b0adca18e3f490c46165e73cb
Reviewed-on: https://chromium-review.googlesource.com/c/1286884
Commit-Queue: Christian Biesinger <cbiesinger@chromium.org>
Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600472}
parent 821bb5d7
......@@ -206,7 +206,7 @@ void NGInlineLayoutAlgorithm::CreateLine(NGLineInfo* line_info,
NGExclusionSpace* exclusion_space) {
// Needs MutableResults to move ShapeResult out of the NGLineInfo.
NGInlineItemResults* line_items = line_info->MutableResults();
line_box_.clear();
line_box_.resize(0);
// Apply justification before placing items, because it affects size/position
// of items, which are needed to compute inline static positions.
......@@ -725,8 +725,8 @@ scoped_refptr<NGLayoutResult> NGInlineLayoutAlgorithm::Layout() {
#endif
// Reset any state that may have been modified in a previous pass.
positioned_floats.clear();
unpositioned_floats_.clear();
positioned_floats.resize(0);
unpositioned_floats_.resize(0);
container_builder_.Reset();
exclusion_space = initial_exclusion_space;
......@@ -876,7 +876,7 @@ void NGInlineLayoutAlgorithm::PositionPendingFloats(
<< "The floats BFC block offset should be known here";
if (BreakToken() && BreakToken()->IgnoreFloats()) {
unpositioned_floats_.clear();
unpositioned_floats_.resize(0);
return;
}
......@@ -896,7 +896,7 @@ void NGInlineLayoutAlgorithm::PositionPendingFloats(
ConstraintSpace(), exclusion_space, &positioned_floats);
positioned_floats_.AppendVector(positioned_floats);
unpositioned_floats_.clear();
unpositioned_floats_.resize(0);
}
void NGInlineLayoutAlgorithm::BidiReorder() {
......
......@@ -733,7 +733,7 @@ static LayoutUnit ComputeContentSize(
nullptr /* container_builder */, &empty_exclusion_space, 0u,
line_opportunity, nullptr /* break_token */);
do {
unpositioned_floats.clear();
unpositioned_floats.resize(0);
NGLineInfo line_info;
line_breaker.NextLine(&line_info);
......
......@@ -26,8 +26,8 @@ NGLineBoxFragmentBuilder::NGLineBoxFragmentBuilder(
NGLineBoxFragmentBuilder::~NGLineBoxFragmentBuilder() = default;
void NGLineBoxFragmentBuilder::Reset() {
children_.clear();
offsets_.clear();
children_.resize(0);
offsets_.resize(0);
metrics_ = NGLineHeightMetrics();
size_.inline_size = LayoutUnit();
}
......
......@@ -130,7 +130,7 @@ class CORE_EXPORT NGLineBoxFragmentBuilder final
void ReserveInitialCapacity(unsigned capacity) {
children_.ReserveInitialCapacity(capacity);
}
void clear() { children_.clear(); }
void clear() { children_.resize(0); }
void resize(wtf_size_t size) { children_.resize(size); }
using iterator = Vector<Child, 16>::iterator;
......
......@@ -2089,7 +2089,7 @@ void NGBlockLayoutAlgorithm::PositionPendingFloats(
AddPositionedFloats(positioned_floats);
unpositioned_floats_.clear();
unpositioned_floats_.resize(0);
}
template <class Vec>
......
......@@ -171,7 +171,7 @@ void NGContainerFragmentBuilder::GetAndClearOutOfFlowDescendantCandidates(
// The descendant may be a "position: absolute" which contains a "position:
// fixed" for example. (This fragment isn't the containing block for the
// fixed descendant).
oof_positioned_candidates_.clear();
oof_positioned_candidates_.resize(0);
}
void NGContainerFragmentBuilder::MoveOutOfFlowDescendantCandidatesToDescendants(
......
......@@ -206,6 +206,10 @@ class CORE_EXPORT NGContainerFragmentBuilder : public NGBaseFragmentBuilder {
child_offset(child_offset_arg),
is_line_relative(true),
line_direction(line_direction_arg) {}
// This constructor is not meant to be called, but required so we can use
// Vector::resize(0).
NGOutOfFlowPositionedCandidate() {}
};
NGContainerFragmentBuilder(scoped_refptr<const ComputedStyle>,
......
......@@ -94,10 +94,10 @@ NGContainerFragmentBuilder& NGFragmentBuilder::AddChild(
}
void NGFragmentBuilder::RemoveChildren() {
child_break_tokens_.clear();
inline_break_tokens_.clear();
children_.clear();
offsets_.clear();
child_break_tokens_.resize(0);
inline_break_tokens_.resize(0);
children_.resize(0);
offsets_.resize(0);
}
NGFragmentBuilder& NGFragmentBuilder::AddBreakBeforeChild(
......
......@@ -74,7 +74,7 @@ void NGOutOfFlowLayoutPart::Run(LayoutBox* only_layout) {
}
// Sweep any descendants that might have been added.
// This happens when an absolute container has a fixed child.
descendant_candidates.clear();
descendant_candidates.resize(0);
container_builder_->GetAndClearOutOfFlowDescendantCandidates(
&descendant_candidates, container_builder_->GetLayoutObject());
}
......
......@@ -33,6 +33,10 @@ struct CORE_EXPORT NGOutOfFlowPositionedDescendant {
: node(node_param),
static_position(static_position_param),
inline_container(inline_container_param) {}
// This constructor is not meant to be called, but required so we can use
// Vector::resize(0).
NGOutOfFlowPositionedDescendant() : node(nullptr) {}
};
} // namespace blink
......
......@@ -15,6 +15,10 @@ class NGLayoutResult;
// Contains the information necessary for copying back data to a FloatingObject.
struct CORE_EXPORT NGPositionedFloat {
// This constructor is not meant to be called, but required so we can use
// Vector::resize(0).
NGPositionedFloat() {}
NGPositionedFloat(scoped_refptr<NGLayoutResult> layout_result,
const NGBfcOffset& bfc_offset);
~NGPositionedFloat();
......
......@@ -20,6 +20,10 @@ struct CORE_EXPORT NGUnpositionedFloat final {
DISALLOW_NEW();
public:
// This constructor is not meant to be called, but required so we can use
// Vector::resize(0).
NGUnpositionedFloat() : node(nullptr) {}
NGUnpositionedFloat(NGBlockNode node, const NGBlockBreakToken* token)
: node(node), token(token) {}
......
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