Bug 1344544 - Use nsTObserverArray for listeners of nsWindowMediator. r=erahm a=gchang
authorXidorn Quan <me@upsuper.org>
Mon, 06 Mar 2017 12:50:52 +1100
changeset 392735 176b346ae76231511ef355cf897d4f0b0b0e0005
parent 392734 387bb50158f349459ceca54377cf4188c94a49ea
child 392736 556ffc2114f73aff3bf6d80f0a6648791c17662b
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm, gchang
bugs1344544
milestone54.0a2
Bug 1344544 - Use nsTObserverArray for listeners of nsWindowMediator. r=erahm a=gchang MozReview-Commit-ID: 2PHwh4Htlhz
xpfe/appshell/nsWindowMediator.cpp
xpfe/appshell/nsWindowMediator.h
--- a/xpfe/appshell/nsWindowMediator.cpp
+++ b/xpfe/appshell/nsWindowMediator.cpp
@@ -76,18 +76,19 @@ NS_IMETHODIMP nsWindowMediator::Register
     return NS_ERROR_FAILURE;
   }
 
   mTimeStamp++;
 
   // Create window info struct and add to list of windows
   nsWindowInfo* windowInfo = new nsWindowInfo(inWindow, mTimeStamp);
 
-  for (nsIWindowMediatorListener* listener : mListeners) {
-    listener->OnOpenWindow(inWindow);
+  ListenerArray::ForwardIterator iter(mListeners);
+  while (iter.HasMore()) {
+    iter.GetNext()->OnOpenWindow(inWindow);
   }
 
   if (mOldestWindow)
     windowInfo->InsertAfter(mOldestWindow->mOlder, nullptr);
   else
     mOldestWindow = windowInfo;
 
   return NS_OK;
@@ -108,19 +109,21 @@ nsresult
 nsWindowMediator::UnregisterWindow(nsWindowInfo *inInfo)
 {
   // Inform the iterators
   uint32_t index = 0;
   while (index < mEnumeratorList.Length()) {
     mEnumeratorList[index]->WindowRemoved(inInfo);
     index++;
   }
-  
-  for (nsIWindowMediatorListener* listener : mListeners) {
-    listener->OnCloseWindow(inInfo->mWindow.get());
+
+  nsIXULWindow* window = inInfo->mWindow.get();
+  ListenerArray::ForwardIterator iter(mListeners);
+  while (iter.HasMore()) {
+    iter.GetNext()->OnCloseWindow(window);
   }
 
   // Remove from the lists and free up 
   if (inInfo == mOldestWindow)
     mOldestWindow = inInfo->mYounger;
   if (inInfo == mTopmostWindow)
     mTopmostWindow = inInfo->mLower;
   inInfo->Unlink(true, true);
@@ -394,18 +397,19 @@ nsWindowMediator::UpdateWindowTimeStamp(
 
 NS_IMETHODIMP
 nsWindowMediator::UpdateWindowTitle(nsIXULWindow* inWindow,
                                     const char16_t* inTitle)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   NS_ENSURE_STATE(mReady);
   if (GetInfoFor(inWindow)) {
-    for (nsIWindowMediatorListener* listener : mListeners) {
-      listener->OnWindowTitleChange(inWindow, inTitle);
+    ListenerArray::ForwardIterator iter(mListeners);
+    while (iter.HasMore()) {
+      iter.GetNext()->OnWindowTitleChange(inWindow, inTitle);
     }
   }
 
   return NS_OK;
 }
 
 /* This method's plan is to intervene only when absolutely necessary.
    We will get requests to place our windows behind unknown windows.
@@ -777,27 +781,27 @@ NS_IMPL_ISUPPORTS(nsWindowMediator,
   nsIObserver,
   nsISupportsWeakReference)
 
 NS_IMETHODIMP
 nsWindowMediator::AddListener(nsIWindowMediatorListener* aListener)
 {
   NS_ENSURE_ARG_POINTER(aListener);
   
-  mListeners.AppendObject(aListener);
+  mListeners.AppendElement(aListener);
   
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindowMediator::RemoveListener(nsIWindowMediatorListener* aListener)
 {
   NS_ENSURE_ARG_POINTER(aListener);
 
-  mListeners.RemoveObject(aListener);
+  mListeners.RemoveElement(aListener);
   
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindowMediator::Observe(nsISupports* aSubject,
                           const char* aTopic,
                           const char16_t* aData)
--- a/xpfe/appshell/nsWindowMediator.h
+++ b/xpfe/appshell/nsWindowMediator.h
@@ -7,17 +7,17 @@
 #define nsWindowMediator_h_
 
 #include "nsCOMPtr.h"
 #include "nsIWindowMediator.h"
 #include "nsIObserver.h"
 #include "nsTArray.h"
 #include "nsXPIDLString.h"
 #include "nsWeakReference.h"
-#include "nsCOMArray.h"
+#include "nsTObserverArray.h"
 
 class nsAppShellWindowEnumerator;
 class nsASXULWindowEarlyToLateEnumerator;
 class nsASDOMWindowEarlyToLateEnumerator;
 class nsASDOMWindowFrontToBackEnumerator;
 class nsASXULWindowFrontToBackEnumerator;
 class nsASDOMWindowBackToFrontEnumerator;
 class nsASXULWindowBackToFrontEnumerator;
@@ -67,12 +67,13 @@ private:
 
   nsTArray<nsAppShellWindowEnumerator*> mEnumeratorList;
   nsWindowInfo *mOldestWindow;
   nsWindowInfo *mTopmostWindow;
   int32_t       mTimeStamp;
   bool          mSortingZOrder;
   bool          mReady;
 
-  nsCOMArray<nsIWindowMediatorListener> mListeners;
+  typedef nsTObserverArray<nsCOMPtr<nsIWindowMediatorListener>> ListenerArray;
+  ListenerArray mListeners;
 };
 
 #endif