summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2018-09-29 17:35:19 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-10-01 08:15:07 +0200
commit89e2ec08b50d88facd0b100a8be04ab56c1f3ad1 (patch)
treec1382e834d0f712e4463d09a6b6275ca3b0f1985 /svl
parent89a60912bba7ffd6f65ea99f4664f343c5025c95 (diff)
don't call back into the SvtBroadcaster when dying
and we don't need to use equal_range on a sorted and uniqued vector, lower_bound will do Change-Id: I3f967c04b43432875e3d4de75e6e87bfdef40dc8 Reviewed-on: https://gerrit.libreoffice.org/61135 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/notify/broadcast.cxx10
-rw-r--r--svl/source/notify/listener.cxx10
2 files changed, 15 insertions, 5 deletions
diff --git a/svl/source/notify/broadcast.cxx b/svl/source/notify/broadcast.cxx
index 237c323e5d0b..62a52dff18c5 100644
--- a/svl/source/notify/broadcast.cxx
+++ b/svl/source/notify/broadcast.cxx
@@ -60,11 +60,11 @@ void SvtBroadcaster::Remove( SvtListener* 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);
+ auto it = std::lower_bound(maListeners.begin(), maListeners.end(), p);
+ if (it != maListeners.end() && *it == p)
+ maListeners.erase(it);
+
if (maListeners.empty())
ListenersGone();
}
@@ -116,7 +116,7 @@ SvtBroadcaster::~SvtBroadcaster()
++dest;
if (dest == maDestructedListeners.end() || *dest != *it)
- (*it)->EndListening(*this);
+ (*it)->BroadcasterDying(*this);
}
}
diff --git a/svl/source/notify/listener.cxx b/svl/source/notify/listener.cxx
index 89306a534a0d..506647784451 100644
--- a/svl/source/notify/listener.cxx
+++ b/svl/source/notify/listener.cxx
@@ -19,6 +19,7 @@
#include <svl/listener.hxx>
#include <svl/broadcast.hxx>
+#include <cassert>
SvtListener::QueryBase::QueryBase( sal_uInt16 nId ) : mnId(nId) {}
SvtListener::QueryBase::~QueryBase() {}
@@ -65,6 +66,15 @@ bool SvtListener::EndListening( SvtBroadcaster& rBroadcaster )
return true;
}
+// called from the SvtBroadcaster destructor, used to avoid calling
+// back into the broadcaster again
+void SvtListener::BroadcasterDying( SvtBroadcaster& rBroadcaster )
+{
+ BroadcastersType::iterator it = maBroadcasters.find(&rBroadcaster);
+ if (it != maBroadcasters.end())
+ maBroadcasters.erase(it);
+}
+
void SvtListener::EndListeningAll()
{
BroadcastersType::iterator it = maBroadcasters.begin();