From a11f6a7556c1c376a37fe3562624fd206abec55a Mon Sep 17 00:00:00 2001 From: Wenduo Zhou Date: Mon, 31 Mar 2014 23:02:33 -0400 Subject: [PATCH] Check sorted status before stable_sort. Refs #9244. --- .../Kernel/src/TimeSeriesProperty.cpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp index 8ac4dabcb031..7f9c524b8089 100644 --- a/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp +++ b/Code/Mantid/Framework/Kernel/src/TimeSeriesProperty.cpp @@ -1788,9 +1788,34 @@ namespace Mantid { if (!m_propSortedFlag) { + // Check whether it is sorted or not + size_t numsize = m_values.size(); + if (numsize <= 1) + { + // Always sorted if number of elements is zero or one + m_propSortedFlag = true; + } + else + { + // Check + m_propSortedFlag = true; + for (size_t i = 1; i < numsize; ++i) + if (m_values[i] < m_values[i-1]) + { + m_propSortedFlag = false; + break; + } + } + } + + if (!m_propSortedFlag) + { + g_log.information("TimeSeriesProperty is not sorted. Sorting is operated on it. "); std::stable_sort(m_values.begin(), m_values.end()); m_propSortedFlag = true; } + + return; } /** Find the index of the entry of time t in the mP vector (sorted)