From e05705fe54697a43a56c6fcad5053041f3d97ab0 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Tue, 11 Sep 2018 10:17:37 +0200 Subject: Replace the custom logic in ObserverList with an nsTObserverArray which has all the necessary logic for stable iteration over a potentially changing list of items. --- xpcom/glue/Observer.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/xpcom/glue/Observer.h b/xpcom/glue/Observer.h index 958e5e4a9..cf9e507dd 100644 --- a/xpcom/glue/Observer.h +++ b/xpcom/glue/Observer.h @@ -7,7 +7,7 @@ #ifndef mozilla_Observer_h #define mozilla_Observer_h -#include "nsTArray.h" +#include "nsTObserverArray.h" namespace mozilla { @@ -48,7 +48,7 @@ public: */ void AddObserver(Observer* aObserver) { - mObservers.AppendElement(aObserver); + mObservers.AppendElementUnlessExists(aObserver); } /** @@ -67,15 +67,15 @@ public: void Broadcast(const T& aParam) { - nsTArray*> observersCopy(mObservers); - uint32_t size = observersCopy.Length(); - for (uint32_t i = 0; i < size; ++i) { - observersCopy[i]->Notify(aParam); + typename nsTObserverArray*>::ForwardIterator iter(mObservers); + while (iter.HasMore()) { + Observer* obs = iter.GetNext(); + obs->Notify(aParam); } } protected: - nsTArray*> mObservers; + nsTObserverArray*> mObservers; }; } // namespace mozilla -- cgit v1.2.3