From cd1e045b3bbf4b3e73baf1cbd60d5131d8691fd5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 19 Feb 2015 22:35:25 -0800 Subject: QString: Don't force unrolling of the tail loop if optimizing for size This is quite good if space isn't a constraint: the unrolling ensures faster execution and limits the number of iterations. But it's long. Both Clang and GCC set the predefined macro __OPTIMIZE_SIZE__ if -Os is in effect. ICC does not; MSVC is untested but there are no macros for this effect listed in its documentation. Change-Id: I1a800c709d3543699131ffff13c48919a9a79ec3 Reviewed-by: Oswald Buddenhagen Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qstring.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index fb7158c5f2..e74a8eebee 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2013 Intel Corporation +** Copyright (C) 2015 Intel Corporation ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -158,7 +158,7 @@ static inline bool qt_ends_with(const QChar *haystack, int haystackLen, static inline bool qt_ends_with(const QChar *haystack, int haystackLen, QLatin1String needle, Qt::CaseSensitivity cs); -#ifdef Q_COMPILER_LAMBDA +#if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) namespace { template struct UnrollTailLoop { @@ -239,7 +239,7 @@ void qt_from_latin1(ushort *dst, const char *str, size_t size) size = size % 16; dst += offset; str += offset; -# ifdef Q_COMPILER_LAMBDA +# if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) return UnrollTailLoop<15>::exec(int(size), [=](int i) { dst[i] = (uchar)str[i]; }); # endif #endif @@ -332,7 +332,7 @@ static void qt_to_latin1(uchar *dst, const ushort *src, int length) dst += offset; src += offset; -# ifdef Q_COMPILER_LAMBDA +# if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) return UnrollTailLoop<15>::exec(length, [=](int i) { dst[i] = (src[i]>0xff) ? '?' : (uchar) src[i]; }); # endif #elif defined(__ARM_NEON__) @@ -470,7 +470,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l) - reinterpret_cast(ptr + distance + idx)->unicode(); } } -# ifdef Q_COMPILER_LAMBDA +# if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) const auto &lambda = [=](int i) -> int { return reinterpret_cast(ptr)[i].unicode() - reinterpret_cast(ptr + distance)[i].unicode(); @@ -602,7 +602,7 @@ static int ucstrncmp(const QChar *a, const uchar *c, int l) uc += offset; c += offset; -# ifdef Q_COMPILER_LAMBDA +# if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) const auto &lambda = [=](int i) { return uc[i] - ushort(c[i]); }; return UnrollTailLoop::exec(e - uc, 0, lambda, lambda); # endif @@ -684,7 +684,7 @@ static int findChar(const QChar *str, int len, QChar ch, int from, } } -# ifdef Q_COMPILER_LAMBDA +# if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) return UnrollTailLoop<7>::exec(e - n, -1, [=](int i) { return n[i] == c; }, [=](int i) { return n - s + i; }); -- cgit v1.2.3