From efb30219a1113ee08bf26160a08b4f721a514fdf Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Sat, 21 Dec 2013 01:41:18 +0100 Subject: 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 --- svl/source/notify/broadcast.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'svl') 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)); -- cgit