Kaydet (Commit) 96a03274 authored tarafından Noel Grandin's avatar Noel Grandin

reserve space before appending to vector in a loop

Change-Id: Ib0017fc2a57ab90596aa494934c9579cae4bf4aa
Reviewed-on: https://gerrit.libreoffice.org/61301
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 5c7de51f
......@@ -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);
......
......@@ -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));
}
};
......
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