Bug 1344544 - Use nsTObserverArray for listeners of nsWindowMediator. r=erahm
authorXidorn Quan <me@upsuper.org>
Mon, 06 Mar 2017 12:50:52 +1100
changeset 346271 07345c5aa0734f345f4166e5b24702ad8da10c1f
parent 346270 817642eb6e45ad0f9e91310d115e53b52432046a
child 346272 7818d19d769d177ed68596d02eb0a10b4d48b7cc
push id87766
push usercbook@mozilla.com
push dateTue, 07 Mar 2017 14:18:49 +0000
treeherdermozilla-inbound@32132a071a4e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1344544
milestone54.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 1344544 - Use nsTObserverArray for listeners of nsWindowMediator. r=erahm 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