Bug 1409152. Add an nsTArray::ContainsSorted method. r=froydnj
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 17 Oct 2017 15:39:59 -0400
changeset 437579 f3fcdeba5f882d9c7f0c4f468da9beb66dc7e657
parent 437578 2ccbc0a2df1d0080d08f61f4b1e202d300e4edb4
child 437580 7ae1c0108e987e22160b5de706eae128f18ef75a
push id8114
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 16:33:21 +0000
treeherdermozilla-beta@73e0d89a540f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1409152
milestone58.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 1409152. Add an nsTArray::ContainsSorted method. r=froydnj
dom/media/TrackUnionStream.cpp
layout/style/nsMediaList.cpp
layout/tables/nsTableFrame.cpp
toolkit/components/extensions/MatchPattern.h
toolkit/components/url-classifier/LookupCache.cpp
xpcom/ds/nsTArray.h
--- a/dom/media/TrackUnionStream.cpp
+++ b/dom/media/TrackUnionStream.cpp
@@ -169,34 +169,34 @@ TrackUnionStream::TrackUnionStream()
                                    "input stream %p track %d, desired id %d",
                                    this, aTrack->GetID(), aPort->GetSource(),
                                    aTrack->GetID(),
                                    aPort->GetDestinationTrackId()));
 
     TrackID id;
     if (IsTrackIDExplicit(id = aPort->GetDestinationTrackId())) {
       MOZ_ASSERT(id >= mNextAvailableTrackID &&
-                 mUsedTracks.BinaryIndexOf(id) == mUsedTracks.NoIndex,
+                 !mUsedTracks.ContainsSorted(id),
                  "Desired destination id taken. Only provide a destination ID "
                  "if you can assure its availability, or we may not be able "
                  "to bind to the correct DOM-side track.");
 #ifdef DEBUG
       AutoTArray<MediaInputPort*, 32> inputs(mInputs);
       inputs.AppendElements(mSuspendedInputs);
       for (size_t i = 0; inputs[i] != aPort; ++i) {
         MOZ_ASSERT(inputs[i]->GetSourceTrackId() != TRACK_ANY,
                    "You are adding a MediaInputPort with a track mapping "
                    "while there already exist generic MediaInputPorts for this "
                    "destination stream. This can lead to TrackID collisions!");
       }
 #endif
       mUsedTracks.InsertElementSorted(id);
     } else if ((id = aTrack->GetID()) &&
                id > mNextAvailableTrackID &&
-               mUsedTracks.BinaryIndexOf(id) == mUsedTracks.NoIndex) {
+               !mUsedTracks.ContainsSorted(id)) {
       // Input id available. Mark it used in mUsedTracks.
       mUsedTracks.InsertElementSorted(id);
     } else {
       // No desired destination id and Input id taken, allocate a new one.
       id = mNextAvailableTrackID;
 
       // Update mNextAvailableTrackID and prune any mUsedTracks members it now
       // covers.
--- a/layout/style/nsMediaList.cpp
+++ b/layout/style/nsMediaList.cpp
@@ -269,17 +269,17 @@ nsDocumentRuleResultCacheKey::Matches(
                        const nsTArray<css::DocumentRule*>& aRules) const
 {
   MOZ_ASSERT(mFinalized);
   MOZ_ASSERT(ArrayIsSorted(mMatchingRules));
   MOZ_ASSERT(ArrayIsSorted(aRules));
 
 #ifdef DEBUG
   for (css::DocumentRule* rule : mMatchingRules) {
-    MOZ_ASSERT(aRules.BinaryIndexOf(rule) != aRules.NoIndex,
+    MOZ_ASSERT(aRules.ContainsSorted(rule),
                "aRules must contain all rules in mMatchingRules");
   }
 #endif
 
   // First check that aPresContext matches all the rules listed in
   // mMatchingRules.
   for (css::DocumentRule* rule : mMatchingRules) {
     if (!rule->UseForPresentation(aPresContext)) {
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -1411,17 +1411,17 @@ PaintRowGroupBackgroundByColIdx(nsTableR
 
   for (nsTableRowFrame* row = aRowGroup->GetFirstRow(); row; row = row->GetNextRow()) {
     auto rowPos = row->GetNormalPosition() + aOffset;
     if (!aBuilder->GetDirtyRect().Intersects(nsRect(rowPos, row->GetSize()))) {
       continue;
     }
     for (nsTableCellFrame* cell = row->GetFirstCell(); cell; cell = cell->GetNextCell()) {
       uint32_t curColIdx = cell->ColIndex();
-      if (!aColIdx.Contains(curColIdx)) {
+      if (!aColIdx.ContainsSorted(curColIdx)) {
         if (curColIdx > aColIdx.LastElement()) {
           // We can just stop looking at this row.
           break;
         }
         continue;
       }
 
       if (!cell->ShouldPaintBackground(aBuilder)) {
--- a/toolkit/components/extensions/MatchPattern.h
+++ b/toolkit/components/extensions/MatchPattern.h
@@ -56,17 +56,17 @@ public:
   bool Contains(const nsACString& aElem) const
   {
     RefPtr<nsAtom> atom = NS_Atomize(aElem);
     return Contains(atom);
   }
 
   bool Contains(const nsAtom* aAtom) const
   {
-    return mElems.BinaryIndexOf(aAtom) != mElems.NoIndex;
+    return mElems.ContainsSorted(aAtom);
   }
 
   bool Intersects(const AtomSet& aOther) const;
 
 
   void Add(nsAtom* aElem);
   void Remove(nsAtom* aElem);
 
--- a/toolkit/components/url-classifier/LookupCache.cpp
+++ b/toolkit/components/url-classifier/LookupCache.cpp
@@ -577,18 +577,17 @@ LookupCacheV2::Has(const Completion& aCo
 
   bool found;
   nsresult rv = mPrefixSet->Contains(prefix, &found);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (found) {
     *aHas = true;
     *aMatchLength = PREFIX_SIZE;
-  } else if (mUpdateCompletions.BinaryIndexOf(aCompletion) !=
-             nsTArray<Completion>::NoIndex) {
+  } else if (mUpdateCompletions.ContainsSorted(aCompletion)) {
     // Completions is found in database, confirm the result
     *aHas = true;
     *aMatchLength = COMPLETE_SIZE;
     *aConfirmed = true;
   }
 
   if (*aHas && !(*aConfirmed)) {
     rv = CheckCache(aCompletion, aHas, aConfirmed);
--- a/xpcom/ds/nsTArray.h
+++ b/xpcom/ds/nsTArray.h
@@ -1144,27 +1144,41 @@ public:
   // @param aComp  The Comparator used to determine element equality.
   // @return       true if the element was found.
   template<class Item, class Comparator>
   bool Contains(const Item& aItem, const Comparator& aComp) const
   {
     return IndexOf(aItem, 0, aComp) != NoIndex;
   }
 
+  // Like Contains(), but assumes a sorted array.
+  template<class Item, class Comparator>
+  bool ContainsSorted(const Item& aItem, const Comparator& aComp) const
+  {
+    return BinaryIndexOf(aItem, aComp) != NoIndex;
+  }
+
   // This method searches for the first element in this array that is equal
   // to the given element.  This method assumes that 'operator==' is defined
   // for elem_type.
   // @param aItem  The item to search for.
   // @return       true if the element was found.
   template<class Item>
   bool Contains(const Item& aItem) const
   {
     return IndexOf(aItem) != NoIndex;
   }
 
+  // Like Contains(), but assumes a sorted array.
+  template<class Item>
+  bool ContainsSorted(const Item& aItem) const
+  {
+    return BinaryIndexOf(aItem) != NoIndex;
+  }
+
   // This method searches for the offset of the first element in this
   // array that is equal to the given element.
   // @param aItem  The item to search for.
   // @param aStart The index to start from.
   // @param aComp  The Comparator used to determine element equality.
   // @return       The index of the found element or NoIndex if not found.
   template<class Item, class Comparator>
   index_type IndexOf(const Item& aItem, index_type aStart,