From b8c7289c45d0e2fe2ba9b3ba7fab35e97fec973f Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Tue, 7 Jun 2022 08:53:42 +0100 Subject: [PATCH] Further small improvement to moving median --- src/common/MovingMedian.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/MovingMedian.h b/src/common/MovingMedian.h index 929fe3c..b574deb 100644 --- a/src/common/MovingMedian.h +++ b/src/common/MovingMedian.h @@ -110,7 +110,14 @@ private: // postcondition: m_sorted contains m_size values, one of which is toPut // (and one instance of toDrop has been removed) int n = P::m_size; - int dropIx = std::lower_bound(m_sorted, m_sorted + n, toDrop) - m_sorted; + int dropIx; + if (toDrop <= m_sorted[0]) { + // this is quite a common short-circuit in situations + // where many values can be (the equivalent of) 0 + dropIx = 0; + } else { + dropIx = std::lower_bound(m_sorted, m_sorted + n, toDrop) - m_sorted; + } #ifdef DEBUG_MM std::cout << "\nbefore: [";