diff options
author | Jan Holesovsky <kendy@collabora.com> | 2013-12-21 01:41:18 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2013-12-21 02:07:32 +0100 |
commit | efb30219a1113ee08bf26160a08b4f721a514fdf (patch) | |
tree | b17d35622295131493d6fe6aa744fc4dfb498650 /svl | |
parent | 0d5d01a4d4d7dbdfaea4cf2a44094b58f09d1baa (diff) |
Speedup destruction of sheets with too many listeners & broadcasters.
Listeners and broadcasters are M:N relationship. If you want to
destruct them, you easily end up in O(M*N) situation; where for every
listener, you iterate all broadcasters, to remove that one listener.
To avoid that, announce to the broadcasters that they are going to die, and the
listeners do not have to bother with removing themselves from the broadcaster.
The broadcaster will not broadcast anything after the PrepareForDesctruction()
call anyway.
Change-Id: I68d78b23e73bcbb944de9139448b2c20dfa14f62
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/notify/broadcast.cxx | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/svl/source/notify/broadcast.cxx b/svl/source/notify/broadcast.cxx index 24b5790c0336..3575c7fb4ef1 100644 --- a/svl/source/notify/broadcast.cxx +++ b/svl/source/notify/broadcast.cxx @@ -81,7 +81,7 @@ void SvtBroadcaster::Add( SvtListener* p ) void SvtBroadcaster::Remove( SvtListener* p ) { - if (mbDisposing) + if (mbAboutToDie || mbDisposing) return; Normalize(); @@ -94,10 +94,10 @@ void SvtBroadcaster::Remove( SvtListener* p ) ListenersGone(); } -SvtBroadcaster::SvtBroadcaster() : mbDisposing(false), mbNormalized(false) {} +SvtBroadcaster::SvtBroadcaster() : mbAboutToDie(false), mbDisposing(false), mbNormalized(false) {} SvtBroadcaster::SvtBroadcaster( const SvtBroadcaster &rBC ) : - maListeners(rBC.maListeners), mbDisposing(false), mbNormalized(rBC.mbNormalized) + maListeners(rBC.maListeners), mbAboutToDie(false), mbDisposing(false), mbNormalized(rBC.mbNormalized) { std::for_each(maListeners.begin(), maListeners.end(), StartListeningHandler(*this)); } @@ -113,6 +113,9 @@ SvtBroadcaster::~SvtBroadcaster() void SvtBroadcaster::Broadcast( const SfxHint &rHint ) { + if (mbAboutToDie) + return; + Normalize(); ListenersType listeners(maListeners); std::for_each(listeners.begin(), listeners.end(), NotifyHandler(*this, rHint)); |