Bug 1159042 - p3. Refactor mDirtyRoots type into a class - r=dbaron
☠☠ backed out by d5a15c64bd40 ☠ ☠
authorGerald Squelart <gsquelart@mozilla.com>
Sun, 25 Nov 2018 22:08:03 +0000
changeset 504595 6a5191742ca1666d8ca6412993195a9096604128
parent 504594 3a86c3e65d440cee062e7ab2446b9f1c35c6fe28
child 504596 080b9ceee8eca10edabc249172d7f113c3642873
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1159042
milestone65.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 1159042 - p3. Refactor mDirtyRoots type into a class - r=dbaron As mDirtyRoots will be accessed through a more cohesive API, this patch hides the storage details (nsTArray) -- but provides almost the same API for now. Differential Revision: https://phabricator.services.mozilla.com/D9489
layout/base/PresShell.cpp
layout/base/nsIPresShell.h
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -585,16 +585,64 @@ public:
   }
 
 private:
   RefPtr<PresShell> mShell;
   AutoWeakFrame mWeakFrame;
   nsIContent** mTargetContent;
 };
 
+void
+nsIPresShell::DirtyRootsList::AppendElement(nsIFrame* aFrame)
+{
+  mList.AppendElement(aFrame);
+}
+
+void
+nsIPresShell::DirtyRootsList::RemoveElement(nsIFrame* aFrame)
+{
+  mList.RemoveElement(aFrame);
+}
+
+void
+nsIPresShell::DirtyRootsList::RemoveElements(nsIFrame* aFrame)
+{
+  mList.RemoveElementsBy([&](nsIFrame* aRoot){ return aRoot == aFrame; });
+}
+
+void
+nsIPresShell::DirtyRootsList::RemoveElementAt(size_t aIndex)
+{
+  return mList.RemoveElementAt(aIndex);
+}
+
+void
+nsIPresShell::DirtyRootsList::Clear()
+{
+  mList.Clear();
+}
+
+bool
+nsIPresShell::DirtyRootsList::Contains(nsIFrame* aFrame) const
+{
+  return mList.Contains(aFrame);
+}
+
+bool
+nsIPresShell::DirtyRootsList::IsEmpty() const
+{
+  return mList.IsEmpty();
+}
+
+size_t
+nsIPresShell::DirtyRootsList::Length() const
+{
+  return mList.Length();
+}
+
 bool PresShell::sDisableNonTestMouseEvents = false;
 
 mozilla::LazyLogModule PresShell::gLog("PresShell");
 
 mozilla::TimeStamp PresShell::sLastInputCreated;
 mozilla::TimeStamp PresShell::sLastInputProcessed;
 
 bool PresShell::sProcessInteractable = false;
@@ -2152,22 +2200,17 @@ PresShell::NotifyDestroyingFrame(nsIFram
 
   if (!mIgnoreFrameDestruction) {
     if (aFrame->HasImageRequest()) {
       mDocument->StyleImageLoader()->DropRequestsForFrame(aFrame);
     }
 
     mFrameConstructor->NotifyDestroyingFrame(aFrame);
 
-    for (int32_t idx = mDirtyRoots.Length(); idx; ) {
-      --idx;
-      if (mDirtyRoots[idx] == aFrame) {
-        mDirtyRoots.RemoveElementAt(idx);
-      }
-    }
+    mDirtyRoots.RemoveElements(aFrame);
 
     // Remove frame properties
     aFrame->DeleteAllProperties();
 
     if (aFrame == mCurrentEventFrame) {
       mCurrentEventContent = aFrame->GetContent();
       mCurrentEventFrame = nullptr;
     }
--- a/layout/base/nsIPresShell.h
+++ b/layout/base/nsIPresShell.h
@@ -1779,18 +1779,39 @@ protected:
   nsPoint                   mVisualViewportOffset;
 
   // A list of stack weak frames. This is a pointer to the last item in the list.
   AutoWeakFrame*            mAutoWeakFrames;
 
   // A hash table of heap allocated weak frames.
   nsTHashtable<nsPtrHashKey<WeakFrame>> mWeakFrames;
 
+  class DirtyRootsList
+  {
+  public:
+    void AppendElement(nsIFrame* aFrame);
+    void RemoveElement(nsIFrame* aFrame);
+    void RemoveElements(nsIFrame* aFrame);
+    void RemoveElementAt(size_t aIndex);
+    void Clear();
+    bool Contains(nsIFrame* aFrame) const;
+    bool IsEmpty() const;
+    size_t Length() const;
+    auto begin() const { return mList.begin(); }
+    auto begin() { return mList.begin(); }
+    auto end() const { return mList.end(); }
+    auto end() { return mList.end(); }
+    auto& operator[](size_t i) { return mList[i]; }
+
+  private:
+    nsTArray<nsIFrame*> mList;
+  };
+
   // Reflow roots that need to be reflowed.
-  nsTArray<nsIFrame*> mDirtyRoots;
+  DirtyRootsList mDirtyRoots;
 
 #ifdef MOZ_GECKO_PROFILER
   // These two fields capture call stacks of any changes that require a restyle
   // or a reflow. Only the first change per restyle / reflow is recorded (the
   // one that caused a call to SetNeedStyleFlush() / SetNeedLayoutFlush()).
   UniqueProfilerBacktrace mStyleCause;
   UniqueProfilerBacktrace mReflowCause;
 #endif