Bug 843925 - Make nsLineLayout::NewPerSpanData() allocation infallible. r=roc
authorMats Palmgren <matspal@gmail.com>
Sat, 23 Feb 2013 11:38:15 +0100
changeset 122754 faae76fd9c07da525e55b6113cbc11a542fa592a
parent 122753 c503b13bbb01a0a6d03d7125abe3a8a85b1d9c62
child 122755 006c88b32c8fe03b6508743ceb5fbe2a59dc8cf2
push id23469
push usermpalmgren@mozilla.com
push dateSat, 23 Feb 2013 10:38:20 +0000
treeherdermozilla-inbound@ffb9e097d950 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs843925
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 843925 - Make nsLineLayout::NewPerSpanData() allocation infallible. r=roc
layout/generic/nsLineLayout.cpp
layout/generic/nsLineLayout.h
--- a/layout/generic/nsLineLayout.cpp
+++ b/layout/generic/nsLineLayout.cpp
@@ -174,18 +174,17 @@ nsLineLayout::BeginLineReflow(nscoord aX
   mLineEndsInBR = false;
   mSpanDepth = 0;
   mMaxTopBoxHeight = mMaxBottomBoxHeight = 0;
 
   if (mGotLineBox) {
     mLineBox->ClearHasBullet();
   }
 
-  PerSpanData* psd;
-  NewPerSpanData(&psd);
+  PerSpanData* psd = NewPerSpanData();
   mCurrentSpan = mRootSpan = psd;
   psd->mReflowState = mBlockReflowState;
   psd->mLeftEdge = aX;
   psd->mX = aX;
   psd->mRightEdge = aX + aWidth;
 
   // If we're in a constrained height frame, then we don't allow a
   // max line box width to take effect.
@@ -345,25 +344,25 @@ nsLineLayout::UpdateBand(const nsRect& a
   }
 
   mTopEdge = aNewAvailSpace.y;
   mImpactedByFloats = true;
 
   mLastFloatWasLetterFrame = nsGkAtoms::letterFrame == aFloatFrame->GetType();
 }
 
-nsresult
-nsLineLayout::NewPerSpanData(PerSpanData** aResult)
+nsLineLayout::PerSpanData*
+nsLineLayout::NewPerSpanData()
 {
   PerSpanData* psd = mSpanFreeList;
-  if (nullptr == psd) {
+  if (!psd) {
     void *mem;
     PL_ARENA_ALLOCATE(mem, &mArena, sizeof(PerSpanData));
-    if (nullptr == mem) {
-      return NS_ERROR_OUT_OF_MEMORY;
+    if (!mem) {
+      NS_RUNTIMEABORT("OOM");
     }
     psd = reinterpret_cast<PerSpanData*>(mem);
   }
   else {
     mSpanFreeList = psd->mNextFreeSpan;
   }
   psd->mParent = nullptr;
   psd->mFrame = nullptr;
@@ -371,62 +370,55 @@ nsLineLayout::NewPerSpanData(PerSpanData
   psd->mLastFrame = nullptr;
   psd->mContainsFloat = false;
   psd->mZeroEffectiveSpanBox = false;
   psd->mHasNonemptyContent = false;
 
 #ifdef DEBUG
   mSpansAllocated++;
 #endif
-  *aResult = psd;
-  return NS_OK;
+  return psd;
 }
 
-nsresult
+void
 nsLineLayout::BeginSpan(nsIFrame* aFrame,
                         const nsHTMLReflowState* aSpanReflowState,
-                        nscoord aLeftEdge,
-                        nscoord aRightEdge,
+                        nscoord aLeftEdge, nscoord aRightEdge,
                         nscoord* aBaseline)
 {
   NS_ASSERTION(aRightEdge != NS_UNCONSTRAINEDSIZE,
                "should no longer be using unconstrained sizes");
 #ifdef NOISY_REFLOW
   nsFrame::IndentBy(stdout, mSpanDepth+1);
   nsFrame::ListTag(stdout, aFrame);
   printf(": BeginSpan leftEdge=%d rightEdge=%d\n", aLeftEdge, aRightEdge);
 #endif
 
-  PerSpanData* psd;
-  nsresult rv = NewPerSpanData(&psd);
-  if (NS_SUCCEEDED(rv)) {
-    // Link up span frame's pfd to point to its child span data
-    PerFrameData* pfd = mCurrentSpan->mLastFrame;
-    NS_ASSERTION(pfd->mFrame == aFrame, "huh?");
-    pfd->mSpan = psd;
+  PerSpanData* psd = NewPerSpanData();
+  // Link up span frame's pfd to point to its child span data
+  PerFrameData* pfd = mCurrentSpan->mLastFrame;
+  NS_ASSERTION(pfd->mFrame == aFrame, "huh?");
+  pfd->mSpan = psd;
 
-    // Init new span
-    psd->mFrame = pfd;
-    psd->mParent = mCurrentSpan;
-    psd->mReflowState = aSpanReflowState;
-    psd->mLeftEdge = aLeftEdge;
-    psd->mX = aLeftEdge;
-    psd->mRightEdge = aRightEdge;
-    psd->mBaseline = aBaseline;
+  // Init new span
+  psd->mFrame = pfd;
+  psd->mParent = mCurrentSpan;
+  psd->mReflowState = aSpanReflowState;
+  psd->mLeftEdge = aLeftEdge;
+  psd->mX = aLeftEdge;
+  psd->mRightEdge = aRightEdge;
+  psd->mBaseline = aBaseline;
 
-    psd->mNoWrap =
-      !aSpanReflowState->frame->StyleText()->WhiteSpaceCanWrap();
-    psd->mDirection = aSpanReflowState->mStyleVisibility->mDirection;
-    psd->mChangedFrameDirection = false;
+  psd->mNoWrap = !aSpanReflowState->frame->StyleText()->WhiteSpaceCanWrap();
+  psd->mDirection = aSpanReflowState->mStyleVisibility->mDirection;
+  psd->mChangedFrameDirection = false;
 
-    // Switch to new span
-    mCurrentSpan = psd;
-    mSpanDepth++;
-  }
-  return rv;
+  // Switch to new span
+  mCurrentSpan = psd;
+  mSpanDepth++;
 }
 
 nscoord
 nsLineLayout::EndSpan(nsIFrame* aFrame)
 {
   NS_ASSERTION(mSpanDepth > 0, "end-span without begin-span");
 #ifdef NOISY_REFLOW
   nsFrame::IndentBy(stdout, mSpanDepth);
--- a/layout/generic/nsLineLayout.h
+++ b/layout/generic/nsLineLayout.h
@@ -63,21 +63,18 @@ public:
    * due to available space for the line boxes changing.
    * @param aX/aY/aWidth/aHeight are the new available
    * space rectangle, relative to the containing block.
    * @param aFloatFrame the float frame that was placed.
    */
   void UpdateBand(const nsRect& aNewAvailableSpace,
                   nsIFrame* aFloatFrame);
 
-  nsresult BeginSpan(nsIFrame* aFrame,
-                     const nsHTMLReflowState* aSpanReflowState,
-                     nscoord aLeftEdge,
-                     nscoord aRightEdge,
-                     nscoord* aBaseline);
+  void BeginSpan(nsIFrame* aFrame, const nsHTMLReflowState* aSpanReflowState,
+                 nscoord aLeftEdge, nscoord aRightEdge, nscoord* aBaseline);
 
   // Returns the width of the span
   nscoord EndSpan(nsIFrame* aFrame);
 
   int32_t GetCurrentSpanCount() const;
 
   void SplitLineTo(int32_t aNewCount);
 
@@ -504,17 +501,20 @@ protected:
 #ifdef DEBUG
   int32_t mSpansAllocated, mSpansFreed;
   int32_t mFramesAllocated, mFramesFreed;
 #endif
   PLArenaPool mArena; // Per span and per frame data, 4 byte aligned
 
   nsresult NewPerFrameData(PerFrameData** aResult);
 
-  nsresult NewPerSpanData(PerSpanData** aResult);
+  /**
+   * Allocate a PerSpanData from the mArena pool. The allocation is infallible.
+   */
+  PerSpanData* NewPerSpanData();
 
   void FreeSpan(PerSpanData* psd);
 
   bool InBlockContext() const {
     return mSpanDepth == 0;
   }
 
   void PushFrame(nsIFrame* aFrame);