From 80bfb8f1ad68c37260a295cd6df98acc571f4fde Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 6 Mar 2017 09:15:31 +0100 Subject: [PATCH] QString: make UnrollTailLoop work with non-int indices The extension of ucstrncmp to size_t will introduce the first user of this loop unrolling construct with size_t indices. Instead of choosing between int and size_t, make the index type a new template argument to facilitate a step-by-step transition from int to size_t users. Change-Id: I9d8fa7aaefa572130403bd19e11f52c58dff0a4d Reviewed-by: Thiago Macieira --- src/corelib/tools/qstring.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 8e7f0e50d3..3c0ad1f3b5 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -165,8 +165,8 @@ static inline bool qt_ends_with(const QChar *haystack, int haystackLen, namespace { template struct UnrollTailLoop { - template - static inline RetType exec(int count, RetType returnIfExited, Functor1 loopCheck, Functor2 returnIfFailed, int i = 0) + template + static inline RetType exec(Number count, RetType returnIfExited, Functor1 loopCheck, Functor2 returnIfFailed, Number i = 0) { /* equivalent to: * while (count--) { @@ -188,18 +188,18 @@ template struct UnrollTailLoop return UnrollTailLoop::exec(count - 1, returnIfExited, loopCheck, returnIfFailed, i + 1); } - template - static inline void exec(int count, Functor code) + template + static inline void exec(Number count, Functor code) { /* equivalent to: - * for (int i = 0; i < count; ++i) + * for (Number i = 0; i < count; ++i) * code(i); */ - exec(count, 0, [=](int i) -> bool { code(i); return false; }, [](int) { return 0; }); + exec(count, 0, [=](Number i) -> bool { code(i); return false; }, [](Number) { return 0; }); } }; -template <> template -inline RetType UnrollTailLoop<0>::exec(int, RetType returnIfExited, Functor1, Functor2, int) +template <> template +inline RetType UnrollTailLoop<0>::exec(Number, RetType returnIfExited, Functor1, Functor2, Number) { return returnIfExited; }