Bug 1141931 part 7 - Move [Auto]RubyTextContainerArray to RubyUtils and merge RubyTextContainerIterator into AutoRubyTextContainerArray. r=dholbert
☠☠ backed out by 44c475f5adc1 ☠ ☠
authorXidorn Quan <quanxunzhen@gmail.com>
Wed, 08 Apr 2015 08:40:31 +1200
changeset 267846 6a914ba0b8ecbdfb11ba96e9776892aa9466b3ac
parent 267845 9cfea55b5e952ce1e09908dc58721fce21c80e4d
child 267847 87281c7ded34ab72a731c5d7a832b416802ef2c1
push id4830
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:18:48 +0000
treeherdermozilla-beta@4c2175bb0420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1141931
milestone40.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 1141931 part 7 - Move [Auto]RubyTextContainerArray to RubyUtils and merge RubyTextContainerIterator into AutoRubyTextContainerArray. r=dholbert
layout/generic/RubyUtils.cpp
layout/generic/RubyUtils.h
layout/generic/nsRubyBaseContainerFrame.cpp
layout/generic/nsRubyBaseContainerFrame.h
layout/generic/nsRubyFrame.cpp
--- a/layout/generic/RubyUtils.cpp
+++ b/layout/generic/RubyUtils.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "RubyUtils.h"
 #include "nsRubyFrame.h"
 #include "nsRubyBaseFrame.h"
 #include "nsRubyTextFrame.h"
 #include "nsRubyBaseContainerFrame.h"
+#include "nsRubyTextContainerFrame.h"
 
 using namespace mozilla;
 
 NS_DECLARE_FRAME_PROPERTY(ReservedISize, nullptr);
 
 union NSCoordValue
 {
   nscoord mCoord;
@@ -41,30 +42,23 @@ RubyUtils::ClearReservedISize(nsIFrame* 
 RubyUtils::GetReservedISize(nsIFrame* aFrame)
 {
   MOZ_ASSERT(IsExpandableRubyBox(aFrame));
   NSCoordValue value;
   value.mPointer = aFrame->Properties().Get(ReservedISize());
   return value.mCoord;
 }
 
-RubyTextContainerIterator::RubyTextContainerIterator(
+AutoRubyTextContainerArray::AutoRubyTextContainerArray(
   nsRubyBaseContainerFrame* aBaseContainer)
 {
-  mFrame = aBaseContainer;
-  Next();
-}
-
-void
-RubyTextContainerIterator::Next()
-{
-  MOZ_ASSERT(mFrame, "Should have checked AtEnd()");
-  mFrame = mFrame->GetNextSibling();
-  if (mFrame && mFrame->GetType() != nsGkAtoms::rubyTextContainerFrame) {
-    mFrame = nullptr;
+  for (nsIFrame* frame = aBaseContainer->GetNextSibling();
+       frame && frame->GetType() == nsGkAtoms::rubyTextContainerFrame;
+       frame = frame->GetNextSibling()) {
+    AppendElement(static_cast<nsRubyTextContainerFrame*>(frame));
   }
 }
 
 RubySegmentEnumerator::RubySegmentEnumerator(nsRubyFrame* aRubyFrame)
 {
   nsIFrame* frame = aRubyFrame->GetFirstPrincipalChild();
   MOZ_ASSERT(!frame ||
              frame->GetType() == nsGkAtoms::rubyBaseContainerFrame);
@@ -79,17 +73,17 @@ RubySegmentEnumerator::Next()
   while (frame && frame->GetType() != nsGkAtoms::rubyBaseContainerFrame) {
     frame = frame->GetNextSibling();
   }
   mBaseContainer = static_cast<nsRubyBaseContainerFrame*>(frame);
 }
 
 RubyColumnEnumerator::RubyColumnEnumerator(
   nsRubyBaseContainerFrame* aBaseContainer,
-  const nsTArray<nsRubyTextContainerFrame*>& aTextContainers)
+  const AutoRubyTextContainerArray& aTextContainers)
   : mAtIntraLevelWhitespace(false)
 {
   const uint32_t rtcCount = aTextContainers.Length();
   mFrames.SetCapacity(rtcCount + 1);
 
   nsIFrame* rbFrame = aBaseContainer->GetFirstPrincipalChild();
   MOZ_ASSERT(!rbFrame || rbFrame->GetType() == nsGkAtoms::rubyBaseFrame);
   mFrames.AppendElement(static_cast<nsRubyContentFrame*>(rbFrame));
--- a/layout/generic/RubyUtils.h
+++ b/layout/generic/RubyUtils.h
@@ -4,25 +4,25 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_RubyUtils_h_
 #define mozilla_RubyUtils_h_
 
 #include "nsTArray.h"
 #include "nsGkAtoms.h"
-#include "nsRubyTextContainerFrame.h"
 
 #define RTC_ARRAY_SIZE 1
 
 class nsRubyFrame;
 class nsRubyBaseFrame;
 class nsRubyTextFrame;
 class nsRubyContentFrame;
 class nsRubyBaseContainerFrame;
+class nsRubyTextContainerFrame;
 
 namespace mozilla {
 
 /**
  * Reserved ISize
  *
  * With some exceptions, each ruby internal box has two isizes, which
  * are the reflowed isize and the final isize. The reflowed isize is
@@ -63,33 +63,24 @@ public:
   }
 
   static void SetReservedISize(nsIFrame* aFrame, nscoord aISize);
   static void ClearReservedISize(nsIFrame* aFrame);
   static nscoord GetReservedISize(nsIFrame* aFrame);
 };
 
 /**
- * This class iterates all ruby text containers paired with
- * the given ruby base container.
+ * This array stores all ruby text containers of the ruby segment
+ * of the given ruby base container.
  */
-class MOZ_STACK_CLASS RubyTextContainerIterator
+class MOZ_STACK_CLASS AutoRubyTextContainerArray final
+  : public nsAutoTArray<nsRubyTextContainerFrame*, RTC_ARRAY_SIZE>
 {
 public:
-  explicit RubyTextContainerIterator(nsRubyBaseContainerFrame* aBaseContainer);
-
-  void Next();
-  bool AtEnd() const { return !mFrame; }
-  nsRubyTextContainerFrame* GetTextContainer() const
-  {
-    return static_cast<nsRubyTextContainerFrame*>(mFrame);
-  }
-
-private:
-  nsIFrame* mFrame;
+  explicit AutoRubyTextContainerArray(nsRubyBaseContainerFrame* aBaseContainer);
 };
 
 /**
  * This enumerator enumerates each ruby segment.
  */
 class MOZ_STACK_CLASS RubySegmentEnumerator
 {
 public:
@@ -122,17 +113,17 @@ struct MOZ_STACK_CLASS RubyColumn
 
 /**
  * This enumerator enumerates ruby columns in a segment.
  */
 class MOZ_STACK_CLASS RubyColumnEnumerator
 {
 public:
   RubyColumnEnumerator(nsRubyBaseContainerFrame* aRBCFrame,
-                       const nsTArray<nsRubyTextContainerFrame*>& aRTCFrames);
+                       const AutoRubyTextContainerArray& aRTCFrames);
 
   void Next();
   bool AtEnd() const;
 
   uint32_t GetLevelCount() const { return mFrames.Length(); }
   nsRubyContentFrame* GetFrameAtLevel(uint32_t aIndex) const;
   void GetColumn(RubyColumn& aColumn) const;
 
--- a/layout/generic/nsRubyBaseContainerFrame.cpp
+++ b/layout/generic/nsRubyBaseContainerFrame.cpp
@@ -148,18 +148,17 @@ CalculateColumnPrefISize(nsRenderingCont
 
 // FIXME Currently we use pref isize of ruby content frames for
 //       computing min isize of ruby frame, which may cause problem.
 //       See bug 1134945.
 /* virtual */ void
 nsRubyBaseContainerFrame::AddInlineMinISize(
   nsRenderingContext *aRenderingContext, nsIFrame::InlineMinISizeData *aData)
 {
-  AutoTextContainerArray textContainers;
-  GetTextContainers(textContainers);
+  AutoRubyTextContainerArray textContainers(this);
 
   for (uint32_t i = 0, iend = textContainers.Length(); i < iend; i++) {
     if (textContainers[i]->IsSpanContainer()) {
       // Since spans are not breakable internally, use our pref isize
       // directly if there is any span.
       nsIFrame::InlinePrefISizeData data;
       AddInlinePrefISize(aRenderingContext, &data);
       aData->currentLine += data.currentLine;
@@ -197,18 +196,17 @@ nsRubyBaseContainerFrame::AddInlineMinIS
     }
   }
 }
 
 /* virtual */ void
 nsRubyBaseContainerFrame::AddInlinePrefISize(
   nsRenderingContext *aRenderingContext, nsIFrame::InlinePrefISizeData *aData)
 {
-  AutoTextContainerArray textContainers;
-  GetTextContainers(textContainers);
+  AutoRubyTextContainerArray textContainers(this);
 
   nscoord sum = 0;
   for (nsIFrame* frame = this; frame; frame = frame->GetNextInFlow()) {
     RubyColumnEnumerator enumerator(
       static_cast<nsRubyBaseContainerFrame*>(frame), textContainers);
     for (; !enumerator.AtEnd(); enumerator.Next()) {
       sum += CalculateColumnPrefISize(aRenderingContext, enumerator);
     }
@@ -230,25 +228,16 @@ nsRubyBaseContainerFrame::IsFrameOfType(
 {
   if (aFlags & eSupportsCSSTransforms) {
     return false;
   }
   return nsContainerFrame::IsFrameOfType(aFlags &
          ~(nsIFrame::eLineParticipant));
 }
 
-void
-nsRubyBaseContainerFrame::GetTextContainers(TextContainerArray& aTextContainers)
-{
-  MOZ_ASSERT(aTextContainers.IsEmpty());
-  for (RubyTextContainerIterator iter(this); !iter.AtEnd(); iter.Next()) {
-    aTextContainers.AppendElement(iter.GetTextContainer());
-  }
-}
-
 /* virtual */ bool
 nsRubyBaseContainerFrame::CanContinueTextRun() const
 {
   return true;
 }
 
 /* virtual */ LogicalSize
 nsRubyBaseContainerFrame::ComputeSize(nsRenderingContext *aRenderingContext,
@@ -270,17 +259,17 @@ nsRubyBaseContainerFrame::GetLogicalBase
 {
   return mBaseline;
 }
 
 struct nsRubyBaseContainerFrame::ReflowState
 {
   bool mAllowInitialLineBreak;
   bool mAllowLineBreak;
-  const TextContainerArray& mTextContainers;
+  const AutoRubyTextContainerArray& mTextContainers;
   const nsHTMLReflowState& mBaseReflowState;
   const nsTArray<UniquePtr<nsHTMLReflowState>>& mTextReflowStates;
 };
 
 /* virtual */ void
 nsRubyBaseContainerFrame::Reflow(nsPresContext* aPresContext,
                                  nsHTMLReflowMetrics& aDesiredSize,
                                  const nsHTMLReflowState& aReflowState,
@@ -293,21 +282,19 @@ nsRubyBaseContainerFrame::Reflow(nsPresC
 
   if (!aReflowState.mLineLayout) {
     NS_ASSERTION(
       aReflowState.mLineLayout,
       "No line layout provided to RubyBaseContainerFrame reflow method.");
     return;
   }
 
-  AutoTextContainerArray textContainers;
-  GetTextContainers(textContainers);
-
   MoveOverflowToChildList();
   // Ask text containers to drain overflows
+  AutoRubyTextContainerArray textContainers(this);
   const uint32_t rtcCount = textContainers.Length();
   for (uint32_t i = 0; i < rtcCount; i++) {
     textContainers[i]->MoveOverflowToChildList();
   }
 
   WritingMode lineWM = aReflowState.mLineLayout->GetWritingMode();
   LogicalSize availSize(lineWM, aReflowState.AvailableISize(),
                         aReflowState.AvailableBSize());
@@ -436,20 +423,20 @@ nsRubyBaseContainerFrame::Reflow(nsPresC
  * This struct stores the continuations after this frame and
  * corresponding text containers. It is used to speed up looking
  * ahead for nonempty continuations.
  */
 struct MOZ_STACK_CLASS nsRubyBaseContainerFrame::PullFrameState
 {
   ContinuationTraversingState mBase;
   nsAutoTArray<ContinuationTraversingState, RTC_ARRAY_SIZE> mTexts;
-  const TextContainerArray& mTextContainers;
+  const AutoRubyTextContainerArray& mTextContainers;
 
   PullFrameState(nsRubyBaseContainerFrame* aBaseContainer,
-                 const TextContainerArray& aTextContainers);
+                 const AutoRubyTextContainerArray& aTextContainers);
 };
 
 nscoord
 nsRubyBaseContainerFrame::ReflowColumns(const ReflowState& aReflowState,
                                         nsReflowStatus& aStatus)
 {
   nsLineLayout* lineLayout = aReflowState.mBaseReflowState.mLineLayout;
   const uint32_t rtcCount = aReflowState.mTextContainers.Length();
@@ -690,33 +677,34 @@ nsRubyBaseContainerFrame::ReflowOneColum
     }
   }
 
   return columnISize;
 }
 
 nsRubyBaseContainerFrame::PullFrameState::PullFrameState(
     nsRubyBaseContainerFrame* aBaseContainer,
-    const TextContainerArray& aTextContainers)
+    const AutoRubyTextContainerArray& aTextContainers)
   : mBase(aBaseContainer)
   , mTextContainers(aTextContainers)
 {
   const uint32_t rtcCount = aTextContainers.Length();
   for (uint32_t i = 0; i < rtcCount; i++) {
     mTexts.AppendElement(aTextContainers[i]);
   }
 }
 
 void
 nsRubyBaseContainerFrame::PullOneColumn(nsLineLayout* aLineLayout,
                                         PullFrameState& aPullFrameState,
                                         RubyColumn& aColumn,
                                         bool& aIsComplete)
 {
-  const TextContainerArray& textContainers = aPullFrameState.mTextContainers;
+  const AutoRubyTextContainerArray& textContainers =
+    aPullFrameState.mTextContainers;
   const uint32_t rtcCount = textContainers.Length();
 
   nsIFrame* nextBase = GetNextInFlowChild(aPullFrameState.mBase);
   MOZ_ASSERT(!nextBase || nextBase->GetType() == nsGkAtoms::rubyBaseFrame);
   aColumn.mBaseFrame = static_cast<nsRubyBaseFrame*>(nextBase);
   aIsComplete = !aColumn.mBaseFrame;
   bool pullingIntraLevelWhitespace =
     aColumn.mBaseFrame && aColumn.mBaseFrame->IsIntraLevelWhitespace();
--- a/layout/generic/nsRubyBaseContainerFrame.h
+++ b/layout/generic/nsRubyBaseContainerFrame.h
@@ -4,26 +4,29 @@
  * version 2.0 (the "License"). You can obtain a copy of the License at
  * http://mozilla.org/MPL/2.0/. */
 
 /* rendering object for CSS "display: ruby-base-container" */
 
 #ifndef nsRubyBaseContainerFrame_h___
 #define nsRubyBaseContainerFrame_h___
 
-#include "RubyUtils.h"
 #include "nsContainerFrame.h"
 
 /**
  * Factory function.
  * @return a newly allocated nsRubyBaseContainerFrame (infallible)
  */
 nsContainerFrame* NS_NewRubyBaseContainerFrame(nsIPresShell* aPresShell,
                                                nsStyleContext* aContext);
 
+namespace mozilla {
+struct RubyColumn;
+}
+
 class nsRubyBaseContainerFrame final : public nsContainerFrame
 {
 public:
   NS_DECL_FRAMEARENA_HELPERS
   NS_DECL_QUERYFRAME_TARGET(nsRubyBaseContainerFrame)
   NS_DECL_QUERYFRAME
 
   // nsIFrame overrides
@@ -56,20 +59,16 @@ public:
 #endif
 
 protected:
   friend nsContainerFrame*
     NS_NewRubyBaseContainerFrame(nsIPresShell* aPresShell,
                                  nsStyleContext* aContext);
   explicit nsRubyBaseContainerFrame(nsStyleContext* aContext) : nsContainerFrame(aContext) {}
 
-  typedef nsTArray<nsRubyTextContainerFrame*> TextContainerArray;
-  typedef nsAutoTArray<nsRubyTextContainerFrame*, RTC_ARRAY_SIZE> AutoTextContainerArray;
-  void GetTextContainers(TextContainerArray& aTextContainers);
-
   struct ReflowState;
   nscoord ReflowColumns(const ReflowState& aReflowState,
                         nsReflowStatus& aStatus);
   nscoord ReflowOneColumn(const ReflowState& aReflowState,
                           uint32_t aColumnIndex,
                           const mozilla::RubyColumn& aColumn,
                           nsReflowStatus& aStatus);
   nscoord ReflowSpans(const ReflowState& aReflowState);
--- a/layout/generic/nsRubyFrame.cpp
+++ b/layout/generic/nsRubyFrame.cpp
@@ -172,20 +172,17 @@ nsRubyFrame::ReflowSegment(nsPresContext
 {
   WritingMode lineWM = aReflowState.mLineLayout->GetWritingMode();
   LogicalSize availSize(lineWM, aReflowState.AvailableISize(),
                         aReflowState.AvailableBSize());
   WritingMode rubyWM = GetWritingMode();
   NS_ASSERTION(!rubyWM.IsOrthogonalTo(lineWM),
                "Ruby frame writing-mode shouldn't be orthogonal to its line");
 
-  nsAutoTArray<nsRubyTextContainerFrame*, RTC_ARRAY_SIZE> textContainers;
-  for (RubyTextContainerIterator iter(aBaseContainer); !iter.AtEnd(); iter.Next()) {
-    textContainers.AppendElement(iter.GetTextContainer());
-  }
+  AutoRubyTextContainerArray textContainers(aBaseContainer);
   const uint32_t rtcCount = textContainers.Length();
 
   nsHTMLReflowMetrics baseMetrics(aReflowState);
   bool pushedFrame;
   aReflowState.mLineLayout->ReflowFrame(aBaseContainer, aStatus,
                                         &baseMetrics, pushedFrame);
 
   if (NS_INLINE_IS_BREAK_BEFORE(aStatus)) {