Kaydet (Commit) 57df32e4 authored tarafından Noel Grandin's avatar Noel Grandin

tdf#125254 Performance: A spreadsheet opens too slow, optimise listener

saves about 0.5s out of a 43s load

And remove the comment in EndListeningAll,
SfxBroadcaster::RemoveListener doesn't have any weird side-effects any
more

Change-Id: Id7c8ac1bed8ff3487cb8f977990d8fac351d7f03
Reviewed-on: https://gerrit.libreoffice.org/72396
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 04b055f1
...@@ -26,15 +26,13 @@ ...@@ -26,15 +26,13 @@
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <deque> #include <vector>
#include <memory> #include <memory>
#include <map> #include <map>
typedef std::deque<SfxBroadcaster*> SfxBroadcasterArr_Impl;
struct SfxListener::Impl struct SfxListener::Impl
{ {
SfxBroadcasterArr_Impl maBCs; std::vector<SfxBroadcaster*> maBCs;
#ifdef DBG_UTIL #ifdef DBG_UTIL
std::map<SfxBroadcaster*, std::unique_ptr<sal::BacktraceState>> std::map<SfxBroadcaster*, std::unique_ptr<sal::BacktraceState>>
maCallStacks; maCallStacks;
...@@ -117,10 +115,10 @@ void SfxListener::StartListening(SfxBroadcaster& rBroadcaster, DuplicateHandling ...@@ -117,10 +115,10 @@ void SfxListener::StartListening(SfxBroadcaster& rBroadcaster, DuplicateHandling
void SfxListener::EndListening( SfxBroadcaster& rBroadcaster, bool bRemoveAllDuplicates ) void SfxListener::EndListening( SfxBroadcaster& rBroadcaster, bool bRemoveAllDuplicates )
{ {
SfxBroadcasterArr_Impl::iterator beginIt = mpImpl->maBCs.begin(); auto beginIt = mpImpl->maBCs.begin();
do do
{ {
SfxBroadcasterArr_Impl::iterator it = std::find( beginIt, mpImpl->maBCs.end(), &rBroadcaster ); auto it = std::find( beginIt, mpImpl->maBCs.end(), &rBroadcaster );
if ( it == mpImpl->maBCs.end() ) if ( it == mpImpl->maBCs.end() )
{ {
break; break;
...@@ -139,13 +137,10 @@ void SfxListener::EndListening( SfxBroadcaster& rBroadcaster, bool bRemoveAllDup ...@@ -139,13 +137,10 @@ void SfxListener::EndListening( SfxBroadcaster& rBroadcaster, bool bRemoveAllDup
void SfxListener::EndListeningAll() void SfxListener::EndListeningAll()
{ {
// Attention: when optimizing this: respect side effects of RemoveListener! std::vector<SfxBroadcaster*> aBroadcasters;
while ( !mpImpl->maBCs.empty() ) std::swap(mpImpl->maBCs, aBroadcasters);
{ for (SfxBroadcaster *pBC : aBroadcasters)
SfxBroadcaster *pBC = mpImpl->maBCs.front();
pBC->RemoveListener(*this); pBC->RemoveListener(*this);
mpImpl->maBCs.pop_front();
}
#ifdef DBG_UTIL #ifdef DBG_UTIL
mpImpl->maCallStacks.clear(); mpImpl->maCallStacks.clear();
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment