Bug 1159042 - p3. Refactor mDirtyRoots type into a class - r=dbaron
authorGerald Squelart <gsquelart@mozilla.com>
Tue, 11 Dec 2018 20:32:14 +0000
changeset 450143 e5b84b579c5403898d390188c877d52831c0cce1
parent 450142 29d8ae277caa061f9eb9c337fa63fb000cd6641d
child 450144 6c1abb10067feb7e8161ee8f0a93a5ef8dc75ff2
push id35190
push userccoroiu@mozilla.com
push dateWed, 12 Dec 2018 05:10:47 +0000
treeherdermozilla-central@5bcbe5232a26 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1159042
milestone66.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
@@ -562,16 +562,42 @@ class MOZ_STACK_CLASS AutoPointerEventTa
   }
 
  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;
@@ -2035,22 +2061,17 @@ void PresShell::NotifyDestroyingFrame(ns
 
   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
@@ -1736,18 +1736,38 @@ class nsIPresShell : public nsStubDocume
 
   // 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