[Libreoffice-commits] core.git: svl/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Oct 2 10:18:53 UTC 2018
svl/source/notify/broadcast.cxx | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
New commits:
commit 0e204fa43128b98e3331f306648ae5eb5af862a2
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Oct 1 14:15:03 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Oct 2 12:18:29 2018 +0200
minor optimisation to SvtBroadcaster::Add
Change-Id: I5ab173cb2517602abc42e715375157fd05fdd55f
Reviewed-on: https://gerrit.libreoffice.org/61203
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
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());
}
More information about the Libreoffice-commits
mailing list