diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-01 14:15:03 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-02 12:18:29 +0200 |
commit | 0e204fa43128b98e3331f306648ae5eb5af862a2 (patch) | |
tree | b790b5fe24577c8ffa5edc89e5734cac51cc81e9 /svl/source/notify | |
parent | 7ea1ebbbfe720e1a6913c208a2cc66f1e3a470ef (diff) |
minor optimisation to SvtBroadcaster::Add
Change-Id: I5ab173cb2517602abc42e715375157fd05fdd55f
Reviewed-on: https://gerrit.libreoffice.org/61203
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl/source/notify')
-rw-r--r-- | svl/source/notify/broadcast.cxx | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/svl/source/notify/broadcast.cxx b/svl/source/notify/broadcast.cxx index 61fd98dff3ec..626a48a332e9 100644 --- a/svl/source/notify/broadcast.cxx +++ b/svl/source/notify/broadcast.cxx @@ -44,8 +44,10 @@ void SvtBroadcaster::Add( SvtListener* p ) assert(!mbAboutToDie && "called after PrepareForDestruction()?"); if (mbDisposing || mbAboutToDie) return; + // only reset mbNormalized if we are going to become unsorted + if (!maListeners.empty() && maListeners.back() > p) + mbNormalized = false; maListeners.push_back(p); - mbNormalized = false; } void SvtBroadcaster::Remove( SvtListener* p ) @@ -73,7 +75,7 @@ void SvtBroadcaster::Remove( SvtListener* p ) ListenersGone(); } -SvtBroadcaster::SvtBroadcaster() : mbAboutToDie(false), mbDisposing(false), mbNormalized(false), mbDestNormalized(false) {} +SvtBroadcaster::SvtBroadcaster() : mbAboutToDie(false), mbDisposing(false), mbNormalized(true), mbDestNormalized(true) {} SvtBroadcaster::SvtBroadcaster( const SvtBroadcaster &rBC ) : mbAboutToDie(false), mbDisposing(false), @@ -82,11 +84,10 @@ SvtBroadcaster::SvtBroadcaster( const SvtBroadcaster &rBC ) : assert(!rBC.mbAboutToDie && "copying an object marked with PrepareForDestruction()?"); assert(!rBC.mbDisposing && "copying an object that is in it's destructor?"); + rBC.Normalize(); // so that insert into ourself is in-order, and therefore we do not need to Normalize() maListeners.reserve(rBC.maListeners.size()); - for (ListenersType::iterator it(rBC.maListeners.begin()); it != rBC.maListeners.end(); ++it) - { - (*it)->StartListening(*this); // this will call back into this->Add() - } + for (SvtListener* p : rBC.maListeners) + p->StartListening(*this); // this will call back into this->Add() } SvtBroadcaster::~SvtBroadcaster() @@ -150,6 +151,7 @@ bool SvtBroadcaster::HasListeners() const void SvtBroadcaster::PrepareForDestruction() { mbAboutToDie = true; + // the reserve() serves two purpose (1) performance (2) makes sure our iterators do not become invalid maDestructedListeners.reserve(maListeners.size()); } |