diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-08-20 17:03:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-08-23 15:11:27 +0200 |
commit | ec940941e0bd7db15c5cf7d43df82226e0d849dc (patch) | |
tree | a876a500dfa6a32bc8b284b3b07525480ba60765 /sc | |
parent | 1d524bc7a331e8381e88cfd1b6dea4678ad32514 (diff) |
tdf#119388 add new UNO listener/broadcaster
so that we only need to fire each event to the exact shape that wants
it, instead of spamming all the shapes.
Takes deleting a column from 20s to 10s for me.
Note that none of the broadcasters are calling disposing(EventObject),
so I did not make XShapeEventListener extend lang::XEventListener.
If a memory leak regression points at this commit, possibly I
missed something.
Change-Id: I2b8db08247d3e0203d41faf77491368168994e4d
Reviewed-on: https://gerrit.libreoffice.org/77857
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/Accessibility/DrawModelBroadcaster.cxx | 36 | ||||
-rw-r--r-- | sc/source/ui/inc/DrawModelBroadcaster.hxx | 9 |
2 files changed, 44 insertions, 1 deletions
diff --git a/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx b/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx index 4cf1567856c5..5b63c9926baf 100644 --- a/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx +++ b/sc/source/ui/Accessibility/DrawModelBroadcaster.cxx @@ -21,6 +21,7 @@ #include <sal/log.hxx> #include <svx/svdmodel.hxx> #include <svx/unomod.hxx> +#include <svx/svdobj.hxx> #include <tools/diagnose_ex.h> using namespace ::com::sun::star; @@ -49,6 +50,30 @@ void SAL_CALL ScDrawModelBroadcaster::removeEventListener( const uno::Reference< maEventListeners.removeInterface( xListener ); } +void SAL_CALL ScDrawModelBroadcaster::addShapeEventListener( + const css::uno::Reference< css::drawing::XShape >& xShape, + const uno::Reference< document::XShapeEventListener >& xListener ) +{ + osl::MutexGuard aGuard(maListenerMutex); + auto rv = maShapeListeners.emplace(xShape, xListener); + assert(rv.second && "duplicate listener?"); + (void)rv; +} + +void SAL_CALL ScDrawModelBroadcaster::removeShapeEventListener( + const css::uno::Reference< css::drawing::XShape >& xShape, + const uno::Reference< document::XShapeEventListener >& xListener ) +{ + osl::MutexGuard aGuard(maListenerMutex); + auto it = maShapeListeners.find(xShape); + if (it != maShapeListeners.end()) + { + assert(it->second == xListener && "removing wrong listener?"); + (void)xListener; + maShapeListeners.erase(it); + } +} + void ScDrawModelBroadcaster::Notify( SfxBroadcaster&, const SfxHint& rHint ) { @@ -73,6 +98,17 @@ void ScDrawModelBroadcaster::Notify( SfxBroadcaster&, TOOLS_WARN_EXCEPTION("sc.ui", "Runtime exception caught while notifying shape"); } } + + // right now, we're only handling the specific event necessary to fix this performance problem + if (pSdrHint->GetKind() == SdrHintKind::ObjectChange) + { + auto pSdrObject = const_cast<SdrObject*>(pSdrHint->GetObject()); + uno::Reference<drawing::XShape> xShape(pSdrObject->getUnoShape(), uno::UNO_QUERY); + osl::MutexGuard aGuard(maListenerMutex); + auto it = maShapeListeners.find(xShape); + if (it != maShapeListeners.end()) + it->second->notifyShapeEvent(aEvent); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/DrawModelBroadcaster.hxx b/sc/source/ui/inc/DrawModelBroadcaster.hxx index 6a967a075075..0d5966b864fa 100644 --- a/sc/source/ui/inc/DrawModelBroadcaster.hxx +++ b/sc/source/ui/inc/DrawModelBroadcaster.hxx @@ -24,14 +24,17 @@ #include <comphelper/interfacecontainer3.hxx> #include <cppuhelper/implbase.hxx> #include <com/sun/star/document/XEventBroadcaster.hpp> +#include <com/sun/star/document/XShapeEventBroadcaster.hpp> +#include <unordered_map> class SdrModel; class ScDrawModelBroadcaster : public SfxListener, - public ::cppu::WeakImplHelper< css::document::XEventBroadcaster > + public ::cppu::WeakImplHelper< css::document::XShapeEventBroadcaster > { mutable ::osl::Mutex maListenerMutex; ::comphelper::OInterfaceContainerHelper3<css::document::XEventListener> maEventListeners; + std::unordered_map<css::uno::Reference< css::drawing::XShape >, css::uno::Reference< css::document::XShapeEventListener >> maShapeListeners; SdrModel *mpDrawModel; public: @@ -39,8 +42,12 @@ public: ScDrawModelBroadcaster( SdrModel *pDrawModel ); virtual ~ScDrawModelBroadcaster() override; + // css::document::XEventBroadcaster virtual void SAL_CALL addEventListener( const css::uno::Reference< css::document::XEventListener >& xListener ) override; virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::document::XEventListener >& xListener ) override; + // css::document::XShapeEventBroadcaster + virtual void SAL_CALL addShapeEventListener( const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::document::XShapeEventListener >& xListener ) override; + virtual void SAL_CALL removeShapeEventListener( const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::document::XShapeEventListener >& xListener ) override; virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; }; |