Bug 1641085 Part 1 - Add move semantic to nsFrameList, and use it on SetOverflowFrames(). r=mats

It's useful to use `std::move()` to indicate the frames' ownership in one list
is transferred to the another list.

For a frame list managed by AutoFrameListPtr, after moving its frames to
another list, it can be automatically deleted when it is going out of
scope.

Differential Revision: https://phabricator.services.mozilla.com/D88455
This commit is contained in:
Ting-Yu Lin 2020-08-29 00:22:16 +00:00
parent cb8cfd084a
commit 0076add365
8 changed files with 31 additions and 10 deletions

View File

@ -925,7 +925,7 @@ void nsFieldSetFrame::EnsureChildContinuation(nsIFrame* aChild,
if (nsFrameList* oc = GetOverflowFrames()) {
oc->AppendFrames(nullptr, nifs);
} else {
SetOverflowFrames(nifs);
SetOverflowFrames(std::move(nifs));
}
}
}

View File

@ -847,9 +847,9 @@ nsColumnSetFrame::ColumnBalanceData nsColumnSetFrame::ReflowChildren(
kidNextInFlow->MarkSubtreeDirty();
// Move any of our leftover columns to our overflow list. Our
// next-in-flow will eventually pick them up.
const nsFrameList& continuationColumns = mFrames.RemoveFramesAfter(child);
nsFrameList continuationColumns = mFrames.RemoveFramesAfter(child);
if (continuationColumns.NotEmpty()) {
SetOverflowFrames(continuationColumns);
SetOverflowFrames(std::move(continuationColumns));
}
child = nullptr;

View File

@ -1636,7 +1636,7 @@ void nsContainerFrame::PushChildren(nsIFrame* aFromChild,
nextInFlow->mFrames.InsertFrames(nextInFlow, nullptr, tail);
} else {
// Add the frames to our overflow list
SetOverflowFrames(tail);
SetOverflowFrames(std::move(tail));
}
}
@ -2043,7 +2043,7 @@ void nsContainerFrame::MergeSortedOverflow(nsFrameList& aList) {
if (overflow) {
MergeSortedFrameLists(*overflow, aList, GetContent());
} else {
SetOverflowFrames(aList);
SetOverflowFrames(std::move(aList));
}
}

View File

@ -564,10 +564,10 @@ class nsContainerFrame : public nsSplittableFrame {
/**
* Set the overflow list. aOverflowFrames must not be an empty list.
*/
void SetOverflowFrames(const nsFrameList& aOverflowFrames) {
void SetOverflowFrames(nsFrameList&& aOverflowFrames) {
MOZ_ASSERT(aOverflowFrames.NotEmpty(), "Shouldn't be called");
SetProperty(OverflowProperty(),
new (PresShell()) nsFrameList(aOverflowFrames));
new (PresShell()) nsFrameList(std::move(aOverflowFrames)));
}
/**

View File

@ -259,9 +259,9 @@ void nsFirstLetterFrame::Reflow(nsPresContext* aPresContext,
if (!IsFloating()) {
CreateNextInFlow(kid);
// And then push it to our overflow list
const nsFrameList& overflow = mFrames.RemoveFramesAfter(kid);
nsFrameList overflow = mFrames.RemoveFramesAfter(kid);
if (overflow.NotEmpty()) {
SetOverflowFrames(overflow);
SetOverflowFrames(std::move(overflow));
}
} else if (!kid->GetNextInFlow()) {
// For floating first letter frames (if a continuation wasn't already

View File

@ -80,8 +80,28 @@ class nsFrameList {
VerifyList();
}
// XXX: Ideally, copy constructor should be removed because a frame should be
// owned by one list.
nsFrameList(const nsFrameList& aOther) = default;
// XXX: ideally, copy assignment should be removed because we should use move
// assignment to transfer the ownership.
nsFrameList& operator=(const nsFrameList& aOther) = default;
/**
* Move the frames in aOther to this list. aOther becomes empty after this
* operation.
*/
nsFrameList(nsFrameList&& aOther)
: mFirstChild(aOther.mFirstChild), mLastChild(aOther.mLastChild) {
aOther.Clear();
VerifyList();
}
nsFrameList& operator=(nsFrameList&& aOther) {
SetFrames(aOther);
return *this;
}
/**
* Infallibly allocate a nsFrameList from the shell arena.
*/

View File

@ -5734,6 +5734,7 @@ template <bool IsLessThanOrEqual(nsIFrame*, nsIFrame*)>
template <bool IsLessThanOrEqual(nsIFrame*, nsIFrame*)>
/* static */ void nsIFrame::SortFrameList(nsFrameList& aFrameList) {
nsIFrame* head = MergeSort<IsLessThanOrEqual>(aFrameList.FirstChild());
aFrameList.Clear();
aFrameList = nsFrameList(head, nsLayoutUtils::GetLastSibling(head));
MOZ_ASSERT(IsFrameListSorted<IsLessThanOrEqual>(aFrameList),
"After we sort a frame list, it should be in sorted order...");

View File

@ -2107,7 +2107,7 @@ void nsTableFrame::PushChildren(const RowGroupArray& aRowGroups,
nextInFlow->mFrames.InsertFrames(nextInFlow, prevSibling, frames);
} else {
// Add the frames to our overflow list.
SetOverflowFrames(frames);
SetOverflowFrames(std::move(frames));
}
}