From 936e13212248e32f92f24765b4dd919610253d6f Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 7 Oct 2016 10:59:11 +0200 Subject: Add optimize-for-size case to ucstrncmp The SSE code had a case where tail-loop unrolling was disabled when optimizing for size. What would be even shorter, is to just do a straight-forward loop over the arrays and compare them. For anything else, we can just go for speed. Change-Id: Ifb31650e10e41409972a38014067dbd2927674c9 Reviewed-by: Thiago Macieira --- src/corelib/tools/qstring.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index bf1bc3e650..26bb0de278 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -446,6 +446,16 @@ extern "C" int qt_ucstrncmp_mips_dsp_asm(const ushort *a, // Unicode case-sensitive compare two same-sized strings static int ucstrncmp(const QChar *a, const QChar *b, int l) { +#ifdef __OPTIMIZE_SIZE__ + const QChar *end = a + l; + while (a < end) { + if (int diff = (int)a->unicode() - (int)b->unicode()) + return diff; + ++a; + ++b; + } + return 0; +#else #if defined(__mips_dsp) if (l >= 8) { return qt_ucstrncmp_mips_dsp_asm(reinterpret_cast(a), @@ -473,7 +483,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l) - reinterpret_cast(ptr + distance + idx)->unicode(); } } -# if defined(Q_COMPILER_LAMBDA) && !defined(__OPTIMIZE_SIZE__) +# if defined(Q_COMPILER_LAMBDA) const auto &lambda = [=](int i) -> int { return reinterpret_cast(ptr)[i].unicode() - reinterpret_cast(ptr + distance)[i].unicode(); @@ -529,6 +539,7 @@ static int ucstrncmp(const QChar *a, const QChar *b, int l) } } return 0; +#endif } static int ucstrncmp(const QChar *a, const uchar *c, int l) -- cgit v1.2.3