diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-09-11 10:17:37 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-09-11 10:17:37 +0200 |
commit | e05705fe54697a43a56c6fcad5053041f3d97ab0 (patch) | |
tree | fa1d84a7ae666f163d9669e7026e0411076febbf | |
parent | 7bf3d2440e8ff65763daedca51aad6d0288ef61d (diff) | |
download | uxp-e05705fe54697a43a56c6fcad5053041f3d97ab0.tar.gz |
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.
-rw-r--r-- | xpcom/glue/Observer.h | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/xpcom/glue/Observer.h b/xpcom/glue/Observer.h index 958e5e4a96..cf9e507dd8 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<T>* aObserver) { - mObservers.AppendElement(aObserver); + mObservers.AppendElementUnlessExists(aObserver); } /** @@ -67,15 +67,15 @@ public: void Broadcast(const T& aParam) { - nsTArray<Observer<T>*> observersCopy(mObservers); - uint32_t size = observersCopy.Length(); - for (uint32_t i = 0; i < size; ++i) { - observersCopy[i]->Notify(aParam); + typename nsTObserverArray<Observer<T>*>::ForwardIterator iter(mObservers); + while (iter.HasMore()) { + Observer<T>* obs = iter.GetNext(); + obs->Notify(aParam); } } protected: - nsTArray<Observer<T>*> mObservers; + nsTObserverArray<Observer<T>*> mObservers; }; } // namespace mozilla |