Bug 1311244 Part 5 - Convert FloatInfo's copy constructor into a move constructor. draft
authorTing-Yu Lin <tlin@mozilla.com>
Fri, 06 Jan 2017 16:36:19 +0800
changeset 459617 031efd094115fea28bfd4ae20004067aff339380
parent 459616 7589ebedab47e9a5fe6d5992433cd6f491e93104
child 459618 ee07ed28684568fc4fd4f47486042e8d64fe5a05
push id41270
push userbmo:tlin@mozilla.com
push dateThu, 12 Jan 2017 09:51:31 +0000
bugs1311244
milestone53.0a1
Bug 1311244 Part 5 - Convert FloatInfo's copy constructor into a move constructor. 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
layout/generic/BlockReflowInput.cpp
layout/generic/nsFloatManager.cpp
layout/generic/nsFloatManager.h
--- a/layout/generic/BlockReflowInput.cpp
+++ b/layout/generic/BlockReflowInput.cpp
@@ -983,19 +983,18 @@ BlockReflowInput::FlowAndPlaceFloat(nsIF
     nsFloatManager::CalculateRegionFor(wm, aFloat, floatMargin,
                                        ContainerSize());
   // if the float split, then take up all of the vertical height
   if (NS_FRAME_IS_NOT_COMPLETE(reflowStatus) &&
       (NS_UNCONSTRAINEDSIZE != ContentBSize())) {
     region.BSize(wm) = std::max(region.BSize(wm),
                                 ContentBSize() - floatPos.B(wm));
   }
-  DebugOnly<nsresult> 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());
 
   // If the float's dimensions have changed, note the damage in the
   // float manager.
   if (!region.IsEqualEdges(oldRegion)) {
     // XXXwaterson conservative: we could probably get away with noting
     // less damage; e.g., if only height has changed, then only note the
--- a/layout/generic/nsFloatManager.cpp
+++ b/layout/generic/nsFloatManager.cpp
@@ -256,17 +256,17 @@ nsFloatManager::GetFlowArea(WritingMode 
                         ? lineLeft - mLineLeft
                         : mLineLeft - lineRight +
                           LogicalSize(aWM, aContainerSize).ISize(aWM);
 
   return nsFlowAreaRect(aWM, inlineStart, blockStart - mBlockStart,
                         lineRight - lineLeft, blockSize, haveFloats);
 }
 
-nsresult
+void
 nsFloatManager::AddFloat(nsIFrame* aFloatFrame, const LogicalRect& aMarginRect,
                          WritingMode aWM, const nsSize& aContainerSize)
 {
   CHECK_BLOCK_AND_LINE_DIR(aWM);
   NS_ASSERTION(aMarginRect.ISize(aWM) >= 0, "negative inline size!");
   NS_ASSERTION(aMarginRect.BSize(aWM) >= 0, "negative block size!");
 
   FloatInfo info(aFloatFrame, mLineLeft, mBlockStart, aMarginRect, aWM,
@@ -285,20 +285,17 @@ nsFloatManager::AddFloat(nsIFrame* aFloa
   MOZ_ASSERT(floatStyle == StyleFloat::Left || floatStyle == StyleFloat::Right,
              "Unexpected float style!");
   nscoord& sideBEnd =
     floatStyle == StyleFloat::Left ? info.mLeftBEnd : info.mRightBEnd;
   nscoord thisBEnd = info.BEnd();
   if (thisBEnd > sideBEnd)
     sideBEnd = thisBEnd;
 
-  if (!mFloats.AppendElement(info))
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  return NS_OK;
+  mFloats.AppendElement(Move(info));
 }
 
 // static
 LogicalRect
 nsFloatManager::CalculateRegionFor(WritingMode          aWM,
                                    nsIFrame*            aFloat,
                                    const LogicalMargin& aMargin,
                                    const nsSize&        aContainerSize)
@@ -572,22 +569,22 @@ nsFloatManager::FloatInfo::FloatInfo(nsI
 
     mShapeBoxRect.emplace(rect.LineLeft(aWM, aContainerSize) + aLineLeft,
                           rect.BStart(aWM) + aBlockStart,
                           rect.ISize(aWM), rect.BSize(aWM));
   }
 }
 
 #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);
 }
 
 nsFloatManager::FloatInfo::~FloatInfo()
 {
   MOZ_COUNT_DTOR(nsFloatManager::FloatInfo);
 }
--- a/layout/generic/nsFloatManager.h
+++ b/layout/generic/nsFloatManager.h
@@ -196,19 +196,19 @@ public:
   /**
    * Add a float that comes after all floats previously added.  Its
    * block start must be even with or below the top of all previous
    * floats.
    *
    * 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
    * had to be pushed to the next page/column?  (If so, we can't place
    * any more floats in this page/column because of the rule that the
    * top of a float cannot be above the top of an earlier float.  It
    * also means that any clear needs to continue to the next column.)
    */
@@ -382,17 +382,17 @@ private:
       const nscoord aBStartCornerRadiusL, const nscoord aBStartCornerRadiusB,
       const nscoord aBEndCornerRadiusL, const nscoord aBEndCornerRadiusB,
       const nscoord aBandBStart, const nscoord aBandBEnd);
 
     static nscoord XInterceptAtY(const nscoord aY, const nscoord aRadiusX,
                                  const nscoord aRadiusY);
 
 #ifdef NS_BUILD_REFCNT_LOGGING
-    FloatInfo(const FloatInfo& aOther);
+    FloatInfo(FloatInfo&& aOther);
     ~FloatInfo();
 #endif
 
     // NB! This is really a logical rect in a writing mode suitable for
     // placing floats, which is not necessarily the actual writing mode
     // either of the block which created the frame manager or the block
     // that is calling the frame manager. The inline coordinates are in
     // the line-relative axis of the frame manager and its block