diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-03 15:23:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-10-04 08:15:48 +0200 |
commit | 96a032743339f315ffff13fd8dc9191acffcc636 (patch) | |
tree | a8b843f07b8249895a5861c3fb5f9c81b3b2e9d4 /sc | |
parent | 5c7de51f908e866cdab7dbf4aa22aa48f42dc153 (diff) |
reserve space before appending to vector in a loop
Change-Id: Ib0017fc2a57ab90596aa494934c9579cae4bf4aa
Reviewed-on: https://gerrit.libreoffice.org/61301
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/data/column.cxx | 19 | ||||
-rw-r--r-- | sc/source/core/data/column4.cxx | 1 |
2 files changed, 6 insertions, 14 deletions
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx index a63cc1193254..2617a72b115b 100644 --- a/sc/source/core/data/column.cxx +++ b/sc/source/core/data/column.cxx @@ -3345,11 +3345,10 @@ namespace { class TransferListenersHandler { public: - typedef std::vector<SvtListener*> ListenersType; struct Entry { size_t mnRow; - ListenersType maListeners; + std::vector<SvtListener*> maListeners; }; typedef std::vector<Entry> ListenerListType; @@ -3362,22 +3361,14 @@ public: { assert(pBroadcaster); - // It's important to make a copy here. - SvtBroadcaster::ListenersType aLis = pBroadcaster->GetAllListeners(); - if (aLis.empty()) + // It's important to make a copy of the broadcasters listener list here + Entry aEntry { nRow, pBroadcaster->GetAllListeners() }; + if (aEntry.maListeners.empty()) // No listeners to transfer. return; - Entry aEntry; - aEntry.mnRow = nRow; - - SvtBroadcaster::ListenersType::iterator it = aLis.begin(), itEnd = aLis.end(); - for (; it != itEnd; ++it) - { - SvtListener* pLis = *it; + for (SvtListener* pLis : aEntry.maListeners) pLis->EndListening(*pBroadcaster); - aEntry.maListeners.push_back(pLis); - } maListenerList.push_back(aEntry); diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx index 608cef4609e2..3fac1ea00947 100644 --- a/sc/source/core/data/column4.cxx +++ b/sc/source/core/data/column4.cxx @@ -1226,6 +1226,7 @@ public: void operator() ( size_t /*nRow*/, SvtBroadcaster* p ) { SvtBroadcaster::ListenersType& rLis = p->GetAllListeners(); + mrListeners.reserve(mrListeners.size() + rLis.size()); std::copy(rLis.begin(), rLis.end(), std::back_inserter(mrListeners)); } }; |