From 9302169bd5ad8380ebe95f50986d2b32eb486901 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Fri, 29 Nov 2013 14:06:50 +0100 Subject: QtConcurrent: Workaround GCC bug 58800 in median calculation 1) Revert 880b614 for libstdc++ <= 4.7.3 || (4.8.0 >= ... <= 4.8.2) 2) Fix off-by-one error in reverted code for Median::_bufferSize <= 2. Task-number: QTBUG-35058 Change-Id: I9d226c2806c1cf06c3d5b9c9f371262d2d69bf2b Reviewed-by: Olivier Goffart Reviewed-by: Marc Mutz --- src/concurrent/qtconcurrentmedian.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/concurrent') diff --git a/src/concurrent/qtconcurrentmedian.h b/src/concurrent/qtconcurrentmedian.h index b39b3ed32b..ce2afb9c28 100644 --- a/src/concurrent/qtconcurrentmedian.h +++ b/src/concurrent/qtconcurrentmedian.h @@ -102,10 +102,19 @@ public: { if (dirty) { dirty = false; + +// This is a workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58800 +// Avoid using std::nth_element for stdlibc++ <= 4.7.3 || (>= 4.8.0 && <= 4.8.2) +#if defined(__GLIBCXX__) && (__GLIBCXX__ <= 20130411 || (__GLIBCXX__ >= 20130322 && __GLIBCXX__ <= 20131016)) + QVector sorted = values; + std::sort(sorted.begin(), sorted.end()); + currentMedian = sorted.at(bufferSize / 2); +#else QVector copy = values; typename QVector::iterator begin = copy.begin(), mid = copy.begin() + bufferSize/2, end = copy.end(); std::nth_element(begin, mid, end); currentMedian = *mid; +#endif } return currentMedian; } -- cgit v1.2.3