From ea61e604fa421e9df5139bb5f478bdf710f05db9 Mon Sep 17 00:00:00 2001 From: Ting-Yu Lin Date: Fri, 6 Jan 2017 16:36:19 +0800 Subject: [PATCH] Bug 1311244 Part 5 - Convert FloatInfo's copy constructor into a move constructor. r=dbaron Use move constructor for two reasons. 1) The copy constructor is needed only when appending FloatInfo to mFloats, so using move constructor will likely be more efficient if some of the member variables support move constructor. 2) Part 6 will added a UniquePtr member to FloatInfo, so using move constructor becomes necessary. Also change the return value of AddFloat() to void to simplify the code, since all the other callers do not check the return value, and BlockReflowInput::FloatAndPlaceFloat() only asserts in debug mode. I assume it's safe to omit the OOM check. MozReview-Commit-ID: GVbbsdBjr7b --HG-- extra : rebase_source : e0f647e029278a5033bb9d6d780e73e32de460d3 --- layout/generic/BlockReflowInput.cpp | 5 ++--- layout/generic/nsFloatManager.cpp | 19 ++++++++----------- layout/generic/nsFloatManager.h | 8 ++++---- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/layout/generic/BlockReflowInput.cpp b/layout/generic/BlockReflowInput.cpp index 15b1b4c631ec..8c081dc44563 100644 --- a/layout/generic/BlockReflowInput.cpp +++ b/layout/generic/BlockReflowInput.cpp @@ -988,9 +988,8 @@ BlockReflowInput::FlowAndPlaceFloat(nsIFrame* aFloat) region.BSize(wm) = std::max(region.BSize(wm), ContentBSize() - floatPos.B(wm)); } - DebugOnly rv = mFloatManager->AddFloat(aFloat, region, wm, - ContainerSize()); - MOZ_ASSERT(NS_SUCCEEDED(rv), "bad float placement"); + mFloatManager->AddFloat(aFloat, region, wm, ContainerSize()); + // store region nsFloatManager::StoreRegionFor(wm, aFloat, region, ContainerSize()); diff --git a/layout/generic/nsFloatManager.cpp b/layout/generic/nsFloatManager.cpp index e0c3366cfde2..cc647db8a747 100644 --- a/layout/generic/nsFloatManager.cpp +++ b/layout/generic/nsFloatManager.cpp @@ -261,7 +261,7 @@ nsFloatManager::GetFlowArea(WritingMode aWM, nscoord aBCoord, nscoord aBSize, lineRight - lineLeft, blockSize, haveFloats); } -nsresult +void nsFloatManager::AddFloat(nsIFrame* aFloatFrame, const LogicalRect& aMarginRect, WritingMode aWM, const nsSize& aContainerSize) { @@ -290,10 +290,7 @@ nsFloatManager::AddFloat(nsIFrame* aFloatFrame, const LogicalRect& aMarginRect, if (thisBEnd > sideBEnd) sideBEnd = thisBEnd; - if (!mFloats.AppendElement(info)) - return NS_ERROR_OUT_OF_MEMORY; - - return NS_OK; + mFloats.AppendElement(Move(info)); } // static @@ -577,12 +574,12 @@ nsFloatManager::FloatInfo::FloatInfo(nsIFrame* aFrame, } #ifdef NS_BUILD_REFCNT_LOGGING -nsFloatManager::FloatInfo::FloatInfo(const FloatInfo& aOther) - : mFrame(aOther.mFrame) - , mLeftBEnd(aOther.mLeftBEnd) - , mRightBEnd(aOther.mRightBEnd) - , mRect(aOther.mRect) - , mShapeBoxRect(aOther.mShapeBoxRect) +nsFloatManager::FloatInfo::FloatInfo(FloatInfo&& aOther) + : mFrame(Move(aOther.mFrame)) + , mLeftBEnd(Move(aOther.mLeftBEnd)) + , mRightBEnd(Move(aOther.mRightBEnd)) + , mRect(Move(aOther.mRect)) + , mShapeBoxRect(Move(aOther.mShapeBoxRect)) { MOZ_COUNT_CTOR(nsFloatManager::FloatInfo); } diff --git a/layout/generic/nsFloatManager.h b/layout/generic/nsFloatManager.h index 3f65bda04c35..c2a7f0afc42c 100644 --- a/layout/generic/nsFloatManager.h +++ b/layout/generic/nsFloatManager.h @@ -201,9 +201,9 @@ public: * aMarginRect is relative to the current translation. The caller * must ensure aMarginRect.height >= 0 and aMarginRect.width >= 0. */ - nsresult AddFloat(nsIFrame* aFloatFrame, - const mozilla::LogicalRect& aMarginRect, - mozilla::WritingMode aWM, const nsSize& aContainerSize); + void AddFloat(nsIFrame* aFloatFrame, + const mozilla::LogicalRect& aMarginRect, + mozilla::WritingMode aWM, const nsSize& aContainerSize); /** * Notify that we tried to place a float that could not fit at all and @@ -387,7 +387,7 @@ private: const nscoord aRadiusY); #ifdef NS_BUILD_REFCNT_LOGGING - FloatInfo(const FloatInfo& aOther); + FloatInfo(FloatInfo&& aOther); ~FloatInfo(); #endif