mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 08:48:39 +09:00
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.
This commit is contained in:
parent
fc1e50d7e9
commit
69c4dd8992
1 changed files with 7 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue