[Libreoffice-commits] core.git: Branch 'private/kohei/xlsx-import-speedup' - include/svl svl/source
Kohei Yoshida
kohei.yoshida at collabora.com
Thu Nov 14 06:50:58 PST 2013
include/svl/broadcast.hxx | 13 +++++++++++--
svl/source/notify/broadcast.cxx | 30 ++++++++++++++++++++++++------
2 files changed, 35 insertions(+), 8 deletions(-)
New commits:
commit 19e18d751861cef375d4d52f751150dbaf41637a
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Thu Nov 14 09:49:15 2013 -0500
Optimize SvtBroadcaster for insertion.
This helps file load performance at the slight overhead during editing.
That said, the overhead during editing is only in theory (not measured) and
shouldn't be that much even in theory.
Change-Id: If22ea34acb0cda311575ac3ed8ce1a8eb69ae33a
diff --git a/include/svl/broadcast.hxx b/include/svl/broadcast.hxx
index 80d9568..6de06d0 100644
--- a/include/svl/broadcast.hxx
+++ b/include/svl/broadcast.hxx
@@ -22,6 +22,7 @@
#include <svl/svldllapi.h>
#include <boost/unordered_set.hpp>
+#include <vector>
class SvtListener;
class SfxHint;
@@ -31,11 +32,18 @@ class SVL_DLLPUBLIC SvtBroadcaster
public:
friend class SvtListener;
- typedef boost::unordered_set<SvtListener*> ListenersType;
+ typedef std::vector<SvtListener*> ListenersType;
private:
const SvtBroadcaster& operator=(const SvtBroadcaster &); // verboten
+ /**
+ * Ensure that the container doesn't contain any duplicated listener
+ * entries. As a side effect, the listeners get sorted by pointer values
+ * after this call.
+ */
+ void Normalize();
+
void Add( SvtListener* p );
void Remove( SvtListener* p );
@@ -55,7 +63,8 @@ public:
private:
ListenersType maListeners;
- bool mbDying;
+ bool mbDisposing:1;
+ bool mbNormalized:1;
};
diff --git a/svl/source/notify/broadcast.cxx b/svl/source/notify/broadcast.cxx
index 7e59e36..96d34a7 100644
--- a/svl/source/notify/broadcast.cxx
+++ b/svl/source/notify/broadcast.cxx
@@ -62,32 +62,49 @@ public:
}
+void SvtBroadcaster::Normalize()
+{
+ if (mbNormalized)
+ return;
+
+ std::sort(maListeners.begin(), maListeners.end());
+ ListenersType::iterator itUniqueEnd = std::unique(maListeners.begin(), maListeners.end());
+ maListeners.erase(itUniqueEnd, maListeners.end());
+ mbNormalized = true;
+}
+
void SvtBroadcaster::Add( SvtListener* p )
{
- maListeners.insert(p);
+ maListeners.push_back(p);
+ mbNormalized = false;
}
void SvtBroadcaster::Remove( SvtListener* p )
{
- if (mbDying)
+ if (mbDisposing)
return;
- maListeners.erase(p);
+ Normalize();
+ std::pair<ListenersType::iterator,ListenersType::iterator> r =
+ std::equal_range(maListeners.begin(), maListeners.end(), p);
+
+ if (r.first != r.second)
+ maListeners.erase(r.first, r.second);
if (maListeners.empty())
ListenersGone();
}
-SvtBroadcaster::SvtBroadcaster() : mbDying(false) {}
+SvtBroadcaster::SvtBroadcaster() : mbDisposing(false), mbNormalized(false) {}
SvtBroadcaster::SvtBroadcaster( const SvtBroadcaster &rBC ) :
- maListeners(rBC.maListeners), mbDying(false)
+ maListeners(rBC.maListeners), mbDisposing(false), mbNormalized(rBC.mbNormalized)
{
std::for_each(maListeners.begin(), maListeners.end(), StartListeningHandler(*this));
}
SvtBroadcaster::~SvtBroadcaster()
{
- mbDying = true;
+ mbDisposing = true;
Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
// unregister all listeners.
@@ -96,6 +113,7 @@ SvtBroadcaster::~SvtBroadcaster()
void SvtBroadcaster::Broadcast( const SfxHint &rHint )
{
+ Normalize();
std::for_each(maListeners.begin(), maListeners.end(), NotifyHandler(*this, rHint));
}
More information about the Libreoffice-commits
mailing list