Bug 1007604 - do not use nsVoidArray in nsViewManager; r=roc
authorArpad Borsos <arpad.borsos@googlemail.com>
Fri, 09 May 2014 10:00:48 +0200
changeset 182353 4eabc2a942a3deeefc94fb9ac997f0930c0d24b8
parent 182308 5700a88f895f615a735b79e20475af388c8df3bb
child 182354 f40a93e561613b2cde140d9e11c6b6a8f572ebb7
push id26759
push userryanvm@gmail.com
push dateFri, 09 May 2014 19:51:49 +0000
treeherdermozilla-central@1f4ae9fdfca8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1007604
milestone32.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 1007604 - do not use nsVoidArray in nsViewManager; r=roc
view/public/nsViewManager.h
view/src/nsViewManager.cpp
--- a/view/public/nsViewManager.h
+++ b/view/public/nsViewManager.h
@@ -5,17 +5,17 @@
 
 #ifndef nsViewManager_h___
 #define nsViewManager_h___
 
 #include "nscore.h"
 #include "nsView.h"
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
-#include "nsVoidArray.h"
+#include "nsTArray.h"
 #include "nsDeviceContext.h"
 #include "nsTArray.h"
 #include "mozilla/EventForwards.h"
 
 class nsIWidget;
 struct nsRect;
 class nsRegion;
 class nsDeviceContext;
@@ -404,20 +404,19 @@ private:
   int32_t           mRefreshDisableCount;
   // Use IsPainting() and SetPainting() to access mPainting.
   bool              mPainting;
   bool              mRecursiveRefreshPending;
   bool              mHasPendingWidgetGeometryChanges;
   bool              mInScroll;
 
   //from here to public should be static and locked... MMP
-  static int32_t           mVMCount;        //number of viewmanagers
 
   //list of view managers
-  static nsVoidArray       *gViewManagers;
+  static nsTArray<nsViewManager*> *gViewManagers;
 };
 
 /**
    Invalidation model:
 
    1) Callers call into the view manager and ask it to invalidate a view.
 
    2) The view manager finds the "right" widget for the view, henceforth called
--- a/view/src/nsViewManager.cpp
+++ b/view/src/nsViewManager.cpp
@@ -47,36 +47,31 @@
 
 using namespace mozilla;
 using namespace mozilla::layers;
 
 #define NSCOORD_NONE      INT32_MIN
 
 #undef DEBUG_MOUSE_LOCATION
 
-int32_t nsViewManager::mVMCount = 0;
-
 // Weakly held references to all of the view managers
-nsVoidArray* nsViewManager::gViewManagers = nullptr;
+nsTArray<nsViewManager*>* nsViewManager::gViewManagers = nullptr;
 uint32_t nsViewManager::gLastUserEventTime = 0;
 
 nsViewManager::nsViewManager()
   : mDelayedResize(NSCOORD_NONE, NSCOORD_NONE)
 {
   mRootViewManager = this;
   if (gViewManagers == nullptr) {
-    NS_ASSERTION(mVMCount == 0, "View Manager count is incorrect");
     // Create an array to hold a list of view managers
-    gViewManagers = new nsVoidArray;
+    gViewManagers = new nsTArray<nsViewManager*>;
   }
  
   gViewManagers->AppendElement(this);
 
-  ++mVMCount;
-
   // NOTE:  we use a zeroing operator new, so all data members are
   // assumed to be cleared here.
   mHasPendingWidgetGeometryChanges = false;
   mRecursiveRefreshPending = false;
 }
 
 nsViewManager::~nsViewManager()
 {
@@ -86,30 +81,27 @@ nsViewManager::~nsViewManager()
     mRootView = nullptr;
   }
 
   if (!IsRootVM()) {
     // We have a strong ref to mRootViewManager
     NS_RELEASE(mRootViewManager);
   }
 
-  NS_ASSERTION((mVMCount > 0), "underflow of viewmanagers");
-  --mVMCount;
+  NS_ASSERTION(gViewManagers != nullptr, "About to use null gViewManagers");
 
 #ifdef DEBUG
   bool removed =
 #endif
     gViewManagers->RemoveElement(this);
-  NS_ASSERTION(removed, "Viewmanager instance not was not in the global list of viewmanagers");
+  NS_ASSERTION(removed, "Viewmanager instance was not in the global list of viewmanagers");
 
-  if (0 == mVMCount) {
+  if (gViewManagers->IsEmpty()) {
     // There aren't any more view managers so
     // release the global array of view managers
-   
-    NS_ASSERTION(gViewManagers != nullptr, "About to delete null gViewManagers");
     delete gViewManagers;
     gViewManagers = nullptr;
   }
 
   mPresShell = nullptr;
 }
 
 // We don't hold a reference to the presentation context because it
@@ -1097,18 +1089,18 @@ nsViewManager::UpdateWidgetGeometry()
 }
 
 void
 nsViewManager::CallWillPaintOnObservers()
 {
   NS_PRECONDITION(IsRootVM(), "Must be root VM for this to be called!");
 
   int32_t index;
-  for (index = 0; index < mVMCount; index++) {
-    nsViewManager* vm = (nsViewManager*)gViewManagers->ElementAt(index);
+  for (index = 0; index < gViewManagers->Length(); index++) {
+    nsViewManager* vm = gViewManagers->ElementAt(index);
     if (vm->RootViewManager() == this) {
       // One of our kids.
       if (vm->mRootView && vm->mRootView->IsEffectivelyVisible()) {
         nsCOMPtr<nsIPresShell> shell = vm->GetPresShell();
         if (shell) {
           shell->WillPaint();
         }
       }