Bug 851834 - Remove nsISupportsArray from layout/xul/tree. r=Neil
authorAlexander J. Vincent <ajvincent@gmail.com>
Tue, 19 Mar 2013 08:46:20 -0700
changeset 125494 9d2e25c5011e741ff743b54ebdad279d5aeb4e37
parent 125493 e6b9b196436fb2d81b8f38c9b203346f863a6d9b
child 125495 e6ef8811bc73911539be371058d5152a30456e58
push id24459
push useremorley@mozilla.com
push dateWed, 20 Mar 2013 11:46:36 +0000
treeherdermozilla-central@1d6fe70c79c5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersNeil
bugs851834
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 851834 - Remove nsISupportsArray from layout/xul/tree. r=Neil
layout/xul/tree/nsTreeBodyFrame.cpp
layout/xul/tree/nsTreeBodyFrame.h
layout/xul/tree/nsTreeStyleCache.cpp
layout/xul/tree/nsTreeStyleCache.h
layout/xul/tree/nsTreeUtils.cpp
layout/xul/tree/nsTreeUtils.h
--- a/layout/xul/tree/nsTreeBodyFrame.cpp
+++ b/layout/xul/tree/nsTreeBodyFrame.cpp
@@ -3,17 +3,16 @@
  * 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 "mozilla/DebugOnly.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/Likely.h"
 
 #include "nsCOMPtr.h"
-#include "nsISupportsArray.h"
 #include "nsPresContext.h"
 #include "nsINameSpaceManager.h"
 
 #include "nsTreeBodyFrame.h"
 #include "nsTreeSelection.h"
 #include "nsTreeImageListener.h"
 
 #include "nsGkAtoms.h"
@@ -123,17 +122,16 @@ nsTreeBodyFrame::nsTreeBodyFrame(nsIPres
  mMouseOverRow(-1),
  mFocused(false),
  mHasFixedRowCount(false),
  mVerticalOverflow(false),
  mHorizontalOverflow(false),
  mReflowCallbackPosted(false)
 {
   mColumns = new nsTreeColumns(nullptr);
-  NS_NewISupportsArray(getter_AddRefs(mScratchArray));
 }
 
 // Destructor
 nsTreeBodyFrame::~nsTreeBodyFrame()
 {
   mImageCache.EnumerateRead(CancelImageRequest, this);
   DetachImageListeners();
   delete mSlots;
@@ -1906,142 +1904,142 @@ nsTreeBodyFrame::EndUpdateBatch()
 
   return NS_OK;
 }
 
 void
 nsTreeBodyFrame::PrefillPropertyArray(int32_t aRowIndex, nsTreeColumn* aCol)
 {
   NS_PRECONDITION(!aCol || aCol->GetFrame(), "invalid column passed");
-  mScratchArray->Clear();
+  mScratchArray.Clear();
   
   // focus
   if (mFocused)
-    mScratchArray->AppendElement(nsGkAtoms::focus);
+    mScratchArray.AppendElement(nsGkAtoms::focus);
 
   // sort
   bool sorted = false;
   mView->IsSorted(&sorted);
   if (sorted)
-    mScratchArray->AppendElement(nsGkAtoms::sorted);
+    mScratchArray.AppendElement(nsGkAtoms::sorted);
 
   // drag session
   if (mSlots && mSlots->mIsDragging)
-    mScratchArray->AppendElement(nsGkAtoms::dragSession);
+    mScratchArray.AppendElement(nsGkAtoms::dragSession);
 
   if (aRowIndex != -1) {
     if (aRowIndex == mMouseOverRow)
-      mScratchArray->AppendElement(nsGkAtoms::hover);
+      mScratchArray.AppendElement(nsGkAtoms::hover);
   
     nsCOMPtr<nsITreeSelection> selection;
     mView->GetSelection(getter_AddRefs(selection));
 
     if (selection) {
       // selected
       bool isSelected;
       selection->IsSelected(aRowIndex, &isSelected);
       if (isSelected)
-        mScratchArray->AppendElement(nsGkAtoms::selected);
+        mScratchArray.AppendElement(nsGkAtoms::selected);
 
       // current
       int32_t currentIndex;
       selection->GetCurrentIndex(&currentIndex);
       if (aRowIndex == currentIndex)
-        mScratchArray->AppendElement(nsGkAtoms::current);
+        mScratchArray.AppendElement(nsGkAtoms::current);
   
       // active
       if (aCol) {
         nsCOMPtr<nsITreeColumn> currentColumn;
         selection->GetCurrentColumn(getter_AddRefs(currentColumn));
         if (aCol == currentColumn)
-          mScratchArray->AppendElement(nsGkAtoms::active);
+          mScratchArray.AppendElement(nsGkAtoms::active);
       }
     }
 
     // container or leaf
     bool isContainer = false;
     mView->IsContainer(aRowIndex, &isContainer);
     if (isContainer) {
-      mScratchArray->AppendElement(nsGkAtoms::container);
+      mScratchArray.AppendElement(nsGkAtoms::container);
 
       // open or closed
       bool isOpen = false;
       mView->IsContainerOpen(aRowIndex, &isOpen);
       if (isOpen)
-        mScratchArray->AppendElement(nsGkAtoms::open);
+        mScratchArray.AppendElement(nsGkAtoms::open);
       else
-        mScratchArray->AppendElement(nsGkAtoms::closed);
+        mScratchArray.AppendElement(nsGkAtoms::closed);
     }
     else {
-      mScratchArray->AppendElement(nsGkAtoms::leaf);
+      mScratchArray.AppendElement(nsGkAtoms::leaf);
     }
 
     // drop orientation
     if (mSlots && mSlots->mDropAllowed && mSlots->mDropRow == aRowIndex) {
       if (mSlots->mDropOrient == nsITreeView::DROP_BEFORE)
-        mScratchArray->AppendElement(nsGkAtoms::dropBefore);
+        mScratchArray.AppendElement(nsGkAtoms::dropBefore);
       else if (mSlots->mDropOrient == nsITreeView::DROP_ON)
-        mScratchArray->AppendElement(nsGkAtoms::dropOn);
+        mScratchArray.AppendElement(nsGkAtoms::dropOn);
       else if (mSlots->mDropOrient == nsITreeView::DROP_AFTER)
-        mScratchArray->AppendElement(nsGkAtoms::dropAfter);
+        mScratchArray.AppendElement(nsGkAtoms::dropAfter);
     }
 
     // odd or even
     if (aRowIndex % 2)
-      mScratchArray->AppendElement(nsGkAtoms::odd);
+      mScratchArray.AppendElement(nsGkAtoms::odd);
     else
-      mScratchArray->AppendElement(nsGkAtoms::even);
+      mScratchArray.AppendElement(nsGkAtoms::even);
 
     nsIContent* baseContent = GetBaseElement();
     if (baseContent && baseContent->HasAttr(kNameSpaceID_None, nsGkAtoms::editing))
-      mScratchArray->AppendElement(nsGkAtoms::editing);
+      mScratchArray.AppendElement(nsGkAtoms::editing);
 
     // multiple columns
     if (mColumns->GetColumnAt(1))
-      mScratchArray->AppendElement(nsGkAtoms::multicol);
+      mScratchArray.AppendElement(nsGkAtoms::multicol);
   }
 
   if (aCol) {
-    mScratchArray->AppendElement(aCol->GetAtom());
+    mScratchArray.AppendElement(aCol->GetAtom());
 
     if (aCol->IsPrimary())
-      mScratchArray->AppendElement(nsGkAtoms::primary);
+      mScratchArray.AppendElement(nsGkAtoms::primary);
 
     if (aCol->GetType() == nsITreeColumn::TYPE_CHECKBOX) {
-      mScratchArray->AppendElement(nsGkAtoms::checkbox);
+      mScratchArray.AppendElement(nsGkAtoms::checkbox);
 
       if (aRowIndex != -1) {
         nsAutoString value;
         mView->GetCellValue(aRowIndex, aCol, value);
         if (value.EqualsLiteral("true"))
-          mScratchArray->AppendElement(nsGkAtoms::checked);
+          mScratchArray.AppendElement(nsGkAtoms::checked);
       }
     }
     else if (aCol->GetType() == nsITreeColumn::TYPE_PROGRESSMETER) {
-      mScratchArray->AppendElement(nsGkAtoms::progressmeter);
+      mScratchArray.AppendElement(nsGkAtoms::progressmeter);
 
       if (aRowIndex != -1) {
         int32_t state;
         mView->GetProgressMode(aRowIndex, aCol, &state);
         if (state == nsITreeView::PROGRESS_NORMAL)
-          mScratchArray->AppendElement(nsGkAtoms::progressNormal);
+          mScratchArray.AppendElement(nsGkAtoms::progressNormal);
         else if (state == nsITreeView::PROGRESS_UNDETERMINED)
-          mScratchArray->AppendElement(nsGkAtoms::progressUndetermined);
+          mScratchArray.AppendElement(nsGkAtoms::progressUndetermined);
       }
     }
 
     // Read special properties from attributes on the column content node
     if (aCol->mContent->AttrValueIs(kNameSpaceID_None,
                                     nsGkAtoms::insertbefore,
                                     nsGkAtoms::_true, eCaseMatters))
-      mScratchArray->AppendElement(nsGkAtoms::insertbefore);
+      mScratchArray.AppendElement(nsGkAtoms::insertbefore);
     if (aCol->mContent->AttrValueIs(kNameSpaceID_None,
                                     nsGkAtoms::insertafter,
                                     nsGkAtoms::_true, eCaseMatters))
-      mScratchArray->AppendElement(nsGkAtoms::insertafter);
+      mScratchArray.AppendElement(nsGkAtoms::insertafter);
   }
 }
 
 nsITheme*
 nsTreeBodyFrame::GetTwistyRect(int32_t aRowIndex,
                                nsTreeColumn* aColumn,
                                nsRect& aImageRect,
                                nsRect& aTwistyRect,
@@ -2412,17 +2410,17 @@ nsTreeBodyFrame::GetImageSourceRect(nsSt
 
   return r;
 }
 
 int32_t nsTreeBodyFrame::GetRowHeight()
 {
   // Look up the correct height.  It is equal to the specified height
   // + the specified margins.
-  mScratchArray->Clear();
+  mScratchArray.Clear();
   nsStyleContext* rowContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreerow);
   if (rowContext) {
     const nsStylePosition* myPosition = rowContext->StylePosition();
 
     nscoord minHeight = 0;
     if (myPosition->mMinHeight.GetUnit() == eStyleUnit_Coord)
       minHeight = myPosition->mMinHeight.GetCoordValue();
 
@@ -2450,17 +2448,17 @@ int32_t nsTreeBodyFrame::GetRowHeight()
   }
 
   return nsPresContext::CSSPixelsToAppUnits(18); // As good a default as any.
 }
 
 int32_t nsTreeBodyFrame::GetIndentation()
 {
   // Look up the correct indentation.  It is equal to the specified indentation width.
-  mScratchArray->Clear();
+  mScratchArray.Clear();
   nsStyleContext* indentContext = GetPseudoStyleContext(nsCSSAnonBoxes::moztreeindentation);
   if (indentContext) {
     const nsStylePosition* myPosition = indentContext->StylePosition();
     if (myPosition->mWidth.GetUnit() == eStyleUnit_Coord)  {
       nscoord val = myPosition->mWidth.GetCoordValue();
       return val;
     }
   }
@@ -4199,21 +4197,18 @@ bool
 nsTreeBodyFrame::PseudoMatches(nsCSSSelector* aSelector)
 {
   // Iterate the class list.  For each item in the list, see if
   // it is contained in our scratch array.  If we have a miss, then
   // we aren't a match.  If all items in the class list are
   // present in the scratch array, then we have a match.
   nsAtomList* curr = aSelector->mClassList;
   while (curr) {
-    int32_t index;
-    mScratchArray->GetIndexOf(curr->mAtom, &index);
-    if (index == -1) {
+    if (!mScratchArray.Contains(curr->mAtom))
       return false;
-    }
     curr = curr->mNext;
   }
   return true;
 }
 
 nsIContent*
 nsTreeBodyFrame::GetBaseElement()
 {
--- a/layout/xul/tree/nsTreeBodyFrame.h
+++ b/layout/xul/tree/nsTreeBodyFrame.h
@@ -539,17 +539,17 @@ protected: // Data Members
 
   // A hashtable that maps from URLs to image request/listener pairs.  The URL
   // is provided by the view or by the style context. The style context
   // represents a resolved :-moz-tree-cell-image (or twisty) pseudo-element.
   // It maps directly to an imgIRequest.
   nsDataHashtable<nsStringHashKey, nsTreeImageCacheEntry> mImageCache;
 
   // A scratch array used when looking up cached style contexts.
-  nsCOMPtr<nsISupportsArray> mScratchArray;
+  AtomArray mScratchArray;
 
   // The index of the first visible row and the # of rows visible onscreen.  
   // The tree only examines onscreen rows, starting from
   // this index and going up to index+pageLength.
   int32_t mTopRowIndex;
   int32_t mPageLength;
 
   // The horizontal scroll position
--- a/layout/xul/tree/nsTreeStyleCache.cpp
+++ b/layout/xul/tree/nsTreeStyleCache.cpp
@@ -1,29 +1,27 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 "nsTreeStyleCache.h"
-#include "nsISupportsArray.h"
 #include "nsStyleSet.h"
 #include "mozilla/dom/Element.h"
 
 // The style context cache impl
 nsStyleContext*
 nsTreeStyleCache::GetStyleContext(nsICSSPseudoComparator* aComparator,
                                   nsPresContext* aPresContext,
                                   nsIContent* aContent, 
                                   nsStyleContext* aContext,
                                   nsIAtom* aPseudoElement,
-                                  nsISupportsArray* aInputWord)
+                                  const AtomArray & aInputWord)
 {
-  uint32_t count;
-  aInputWord->Count(&count);
+  uint32_t count = aInputWord.Length();
   nsDFAState startState(0);
   nsDFAState* currState = &startState;
 
   // Go ahead and init the transition table.
   if (!mTransitionTable) {
     // Automatic miss. Build the table
     mTransitionTable =
       new nsObjectHashtable(nullptr, nullptr, DeleteDFAState, nullptr);
@@ -36,18 +34,17 @@ nsTreeStyleCache::GetStyleContext(nsICSS
   if (!currState) {
     // We had a miss. Make a new state and add it to our hash.
     currState = new nsDFAState(mNextState);
     mNextState++;
     mTransitionTable->Put(&key, currState);
   }
 
   for (uint32_t i = 0; i < count; i++) {
-    nsCOMPtr<nsIAtom> pseudo = do_QueryElementAt(aInputWord, i);
-    nsTransitionKey key(currState->GetStateID(), pseudo);
+    nsTransitionKey key(currState->GetStateID(), aInputWord[i]);
     currState = static_cast<nsDFAState*>(mTransitionTable->Get(&key));
 
     if (!currState) {
       // We had a miss. Make a new state and add it to our hash.
       currState = new nsDFAState(mNextState);
       mNextState++;
       mTransitionTable->Put(&key, currState);
     }
--- a/layout/xul/tree/nsTreeStyleCache.h
+++ b/layout/xul/tree/nsTreeStyleCache.h
@@ -3,20 +3,21 @@
  * 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 nsTreeStyleCache_h__
 #define nsTreeStyleCache_h__
 
 #include "nsHashtable.h"
 #include "nsIAtom.h"
+#include "nsCOMArray.h"
 #include "nsICSSPseudoComparator.h"
 #include "nsStyleContext.h"
 
-class nsISupportsArray;
+typedef nsCOMArray<nsIAtom> AtomArray;
 
 class nsDFAState : public nsHashKey
 {
 public:
   uint32_t mStateID;
 
   nsDFAState(uint32_t aID) :mStateID(aID) {}
 
@@ -69,17 +70,17 @@ public:
 
   void Clear() { delete mTransitionTable; mTransitionTable = nullptr; delete mCache; mCache = nullptr; mNextState = 0; }
 
   nsStyleContext* GetStyleContext(nsICSSPseudoComparator* aComparator,
                                   nsPresContext* aPresContext, 
                                   nsIContent* aContent, 
                                   nsStyleContext* aContext,
                                   nsIAtom* aPseudoElement,
-                                  nsISupportsArray* aInputWord);
+                                  const AtomArray & aInputWord);
 
   static bool DeleteDFAState(nsHashKey *aKey, void *aData, void *closure);
 
   static bool ReleaseStyleContext(nsHashKey *aKey, void *aData, void *closure);
 
 protected:
   // A transition table for a deterministic finite automaton.  The DFA
   // takes as its input a single pseudoelement and an ordered set of properties.  
--- a/layout/xul/tree/nsTreeUtils.cpp
+++ b/layout/xul/tree/nsTreeUtils.cpp
@@ -8,22 +8,18 @@
 #include "nsChildIterator.h"
 #include "nsCRT.h"
 #include "nsIAtom.h"
 #include "nsINameSpaceManager.h"
 #include "nsGkAtoms.h"
 #include "nsINodeInfo.h"
 
 nsresult
-nsTreeUtils::TokenizeProperties(const nsAString& aProperties, nsISupportsArray* aPropertiesArray)
+nsTreeUtils::TokenizeProperties(const nsAString& aProperties, AtomArray & aPropertiesArray)
 {
-  NS_PRECONDITION(aPropertiesArray != nullptr, "null ptr");
-  if (! aPropertiesArray)
-     return NS_ERROR_NULL_POINTER;
-
   nsAString::const_iterator end;
   aProperties.EndReading(end);
 
   nsAString::const_iterator iter;
   aProperties.BeginReading(iter);
 
   do {
     // Skip whitespace
@@ -42,17 +38,17 @@ nsTreeUtils::TokenizeProperties(const ns
       ++iter;
 
     // XXX this would be nonsensical
     NS_ASSERTION(iter != first, "eh? something's wrong here");
     if (iter == first)
       break;
 
     nsCOMPtr<nsIAtom> atom = do_GetAtom(Substring(first, iter));
-    aPropertiesArray->AppendElement(atom);
+    aPropertiesArray.AppendElement(atom);
   } while (iter != end);
 
   return NS_OK;
 }
 
 nsIContent*
 nsTreeUtils::GetImmediateChild(nsIContent* aContainer, nsIAtom* aTag)
 {
--- a/layout/xul/tree/nsTreeUtils.h
+++ b/layout/xul/tree/nsTreeUtils.h
@@ -2,28 +2,28 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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 nsTreeUtils_h__
 #define nsTreeUtils_h__
 
 #include "nsString.h"
-#include "nsISupportsArray.h"
+#include "nsTreeStyleCache.h"
 #include "nsIContent.h"
 
 class nsTreeUtils
 {
   public:
     /**
      * Parse a whitespace separated list of properties into an array
      * of atoms.
      */
     static nsresult
-    TokenizeProperties(const nsAString& aProperties, nsISupportsArray* aPropertiesArray);
+    TokenizeProperties(const nsAString& aProperties, AtomArray & aPropertiesArray);
 
     static nsIContent*
     GetImmediateChild(nsIContent* aContainer, nsIAtom* aTag);
 
     static nsIContent*
     GetDescendantChild(nsIContent* aContainer, nsIAtom* aTag);
 
     static nsresult