diff options
Diffstat (limited to 'svl/source/notify/broadcast.cxx')
-rw-r--r-- | svl/source/notify/broadcast.cxx | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/svl/source/notify/broadcast.cxx b/svl/source/notify/broadcast.cxx index 94ef1588e016..cc1ffcb10917 100644 --- a/svl/source/notify/broadcast.cxx +++ b/svl/source/notify/broadcast.cxx @@ -20,6 +20,7 @@ #include <svl/broadcast.hxx> #include <svl/listener.hxx> #include <svl/hint.hxx> +#include <o3tl/safeint.hxx> #include <cassert> #include <algorithm> @@ -27,8 +28,24 @@ void SvtBroadcaster::Normalize() const { if (!mbNormalized) { - std::sort(maListeners.begin(), maListeners.end()); - mbNormalized = true; + // Add() only appends new values, so often the container will be sorted expect for one + // or few last items. For larger containers it is much more efficient to just sort + // the unsorted part and then merge. + if(maListeners.size() > 100) + { + auto sortedEnd = std::is_sorted_until(maListeners.begin(),maListeners.end()); + if( o3tl::make_unsigned( sortedEnd - maListeners.begin()) > maListeners.size() * 3 / 4 ) + { + std::sort( sortedEnd, maListeners.end()); + std::inplace_merge( maListeners.begin(), sortedEnd, maListeners.end()); + mbNormalized = true; + } + } + if (!mbNormalized) + { + std::sort(maListeners.begin(), maListeners.end()); + mbNormalized = true; + } } if (!mbDestNormalized) |