diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-06-01 14:22:57 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-06-11 18:24:29 +0200 |
commit | 7c66fc45239d2589e90fd694d54b3ff826b1bd15 (patch) | |
tree | 064a3ba4eaeaf05ae13ebcebfc6d8beb9234d8f2 /svl/source/notify | |
parent | 3a6d360b5e585b8e92cc0d58d5fbc497448e11fb (diff) |
use internal iterator for SfxBroadcaster
So we can avoid exposing the internal listener vector.
(which allows further optimisations)
Change-Id: If288141a37314dcc01d203029dc51c71ec2b7f54
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152857
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl/source/notify')
-rw-r--r-- | svl/source/notify/SfxBroadcaster.cxx | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/svl/source/notify/SfxBroadcaster.cxx b/svl/source/notify/SfxBroadcaster.cxx index ae1be1475c91..c1c5bee51f34 100644 --- a/svl/source/notify/SfxBroadcaster.cxx +++ b/svl/source/notify/SfxBroadcaster.cxx @@ -131,16 +131,33 @@ void SfxBroadcaster::RemoveListener(SfxListener& rListener) m_RemovedPositions.push_back(positionOfRemovedElement); } -bool SfxBroadcaster::HasListeners() const { return (GetListenerCount() != 0); } +void SfxBroadcaster::ForAllListeners(std::function<bool(SfxListener*)> f) const +{ + for (size_t i = 0; i < m_Listeners.size(); ++i) + { + SfxListener* const pListener = m_Listeners[i]; + if (pListener) + f(pListener); + } +} -size_t SfxBroadcaster::GetListenerCount() const +std::vector<SfxListener*> SfxBroadcaster::GetListenersForUnitTest() const { - assert(m_Listeners.size() >= m_RemovedPositions.size()); - return m_Listeners.size() - m_RemovedPositions.size(); + std::vector<SfxListener*> rv; + for (size_t i = 0; i < m_Listeners.size(); ++i) + { + SfxListener* const pListener = m_Listeners[i]; + if (pListener) + rv.push_back(pListener); + } + return rv; } -size_t SfxBroadcaster::GetSizeOfVector() const { return m_Listeners.size(); } +bool SfxBroadcaster::HasListeners() const { return GetListenerCount() != 0; } -SfxListener* SfxBroadcaster::GetListener(size_t nNo) const { return m_Listeners[nNo]; } +size_t SfxBroadcaster::GetListenerCount() const +{ + return m_Listeners.size() - m_RemovedPositions.size(); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |