Bug 815671 part 7. Fixes to layout code to not copy arrays implicitly. r=roc
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 29 Nov 2012 11:14:14 -0500
changeset 123608 414f6acb19860ff6440e3cb314a83c8e39ab5fc7
parent 123607 ef768d59bb71ec6d08ba456c609ee5e16a0a8c7a
child 123609 ae518bf8df998b623b409caf7682237a0b494481
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs815671
milestone20.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 815671 part 7. Fixes to layout code to not copy arrays implicitly. r=roc
layout/generic/nsFlexContainerFrame.cpp
layout/ipc/RenderFrameParent.cpp
layout/style/nsCSSRules.h
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -1291,36 +1291,33 @@ nsFlexContainerFrame::ResolveFlexibleLen
 #ifdef DEBUG
   for (uint32_t i = 0; i < aItems.Length(); ++i) {
     MOZ_ASSERT(aItems[i].IsFrozen(),
                "All flexible lengths should've been resolved");
   }
 #endif // DEBUG
 }
 
-const nsTArray<SortableFrame>
-BuildSortedChildArray(const nsFrameList& aChildren)
+void
+BuildSortedChildArray(const nsFrameList& aChildren,
+		      nsTArray<SortableFrame>& aSortedChildren)
 {
-  // NOTE: To benefit from Return Value Optimization, we must only return
-  // this value:
-  nsTArray<SortableFrame> sortedChildArray(aChildren.GetLength());
+  aSortedChildren.SetCapacity(aChildren.GetLength());
 
   // Throw all our children in the array...
   uint32_t indexInFrameList = 0;
   for (nsFrameList::Enumerator e(aChildren); !e.AtEnd(); e.Next()) {
     int32_t orderValue = e.get()->GetStylePosition()->mOrder;
-    sortedChildArray.AppendElement(SortableFrame(e.get(), orderValue,
-                                                 indexInFrameList));
+    aSortedChildren.AppendElement(SortableFrame(e.get(), orderValue,
+						indexInFrameList));
     indexInFrameList++;
   }
 
   // ... and sort (by 'order' property)
-  sortedChildArray.Sort();
-
-  return sortedChildArray;
+  aSortedChildren.Sort();
 }
 
 MainAxisPositionTracker::
   MainAxisPositionTracker(nsFlexContainerFrame* aFlexContainerFrame,
                           const FlexboxAxisTracker& aAxisTracker,
                           const nsHTMLReflowState& aReflowState,
                           const nsTArray<FlexItem>& aItems)
   : PositionTracker(aAxisTracker.GetMainAxis()),
@@ -1782,17 +1779,18 @@ nsFlexContainerFrame::GenerateFlexItems(
   nsPresContext* aPresContext,
   const nsHTMLReflowState& aReflowState,
   const FlexboxAxisTracker& aAxisTracker,
   nsTArray<FlexItem>& aFlexItems)
 {
   MOZ_ASSERT(aFlexItems.IsEmpty(), "Expecting outparam to start out empty");
 
   // Sort by 'order' property:
-  const nsTArray<SortableFrame> sortedChildren = BuildSortedChildArray(mFrames);
+  nsTArray<SortableFrame> sortedChildren;
+  BuildSortedChildArray(mFrames, sortedChildren);
 
   // Build list of unresolved flex items:
 
   // XXXdholbert When we support multi-line, we  might want this to be a linked
   // list, so we can easily split into multiple lines.
   aFlexItems.SetCapacity(sortedChildren.Length());
   for (uint32_t i = 0; i < sortedChildren.Length(); ++i) {
     nsresult rv = AppendFlexItemForChild(aPresContext,
--- a/layout/ipc/RenderFrameParent.cpp
+++ b/layout/ipc/RenderFrameParent.cpp
@@ -876,17 +876,17 @@ RenderFrameParent::TriggerRepaint()
   }
 
   docFrame->SchedulePaint();
 }
 
 ShadowLayersParent*
 RenderFrameParent::GetShadowLayers() const
 {
-  const nsTArray<PLayersParent*>& shadowParents = ManagedPLayersParent();
+  const InfallibleTArray<PLayersParent*>& shadowParents = ManagedPLayersParent();
   NS_ABORT_IF_FALSE(shadowParents.Length() <= 1,
                     "can only support at most 1 ShadowLayersParent");
   return (shadowParents.Length() == 1) ?
     static_cast<ShadowLayersParent*>(shadowParents[0]) : nullptr;
 }
 
 uint64_t
 RenderFrameParent::GetLayerTreeId() const
--- a/layout/style/nsCSSRules.h
+++ b/layout/style/nsCSSRules.h
@@ -349,17 +349,17 @@ protected:
   nsCSSKeyframeRule *mRule;
 };
 
 class nsCSSKeyframeRule MOZ_FINAL : public mozilla::css::Rule,
                                     public nsIDOMMozCSSKeyframeRule
 {
 public:
   // WARNING: Steals the contents of aKeys *and* aDeclaration
-  nsCSSKeyframeRule(nsTArray<float> aKeys,
+  nsCSSKeyframeRule(InfallibleTArray<float>& aKeys,
                     nsAutoPtr<mozilla::css::Declaration> aDeclaration)
     : mDeclaration(aDeclaration)
   {
     mKeys.SwapElements(aKeys);
   }
 private:
   nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy);
   ~nsCSSKeyframeRule();
@@ -387,17 +387,17 @@ public:
 
   void ChangeDeclaration(mozilla::css::Declaration* aDeclaration);
 
   virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const MOZ_OVERRIDE;
 
   void DoGetKeyText(nsAString &aKeyText) const;
 
 private:
-  nsAutoTArray<float, 1>                     mKeys;
+  nsTArray<float>                            mKeys;
   nsAutoPtr<mozilla::css::Declaration>       mDeclaration;
   // lazily created when needed:
   nsRefPtr<nsCSSKeyframeStyleDeclaration>    mDOMDeclaration;
 };
 
 class nsCSSKeyframesRule MOZ_FINAL : public mozilla::css::GroupRule,
                                      public nsIDOMMozCSSKeyframesRule
 {