diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-03-06 09:15:31 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-03-06 10:55:04 +0000 |
commit | 80bfb8f1ad68c37260a295cd6df98acc571f4fde (patch) | |
tree | 2dde40e53b28433ffa3abf724014bd1a286919a3 /src/corelib/tools/qstring.cpp | |
parent | a4bec7b388b6d98244293c34ebffb0d73f205c30 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 16 |
1 files 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 <uint MaxCount> struct UnrollTailLoop { - template <typename RetType, typename Functor1, typename Functor2> - static inline RetType exec(int count, RetType returnIfExited, Functor1 loopCheck, Functor2 returnIfFailed, int i = 0) + template <typename RetType, typename Functor1, typename Functor2, typename Number> + static inline RetType exec(Number count, RetType returnIfExited, Functor1 loopCheck, Functor2 returnIfFailed, Number i = 0) { /* equivalent to: * while (count--) { @@ -188,18 +188,18 @@ template <uint MaxCount> struct UnrollTailLoop return UnrollTailLoop<MaxCount - 1>::exec(count - 1, returnIfExited, loopCheck, returnIfFailed, i + 1); } - template <typename Functor> - static inline void exec(int count, Functor code) + template <typename Functor, typename Number> + 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 <typename RetType, typename Functor1, typename Functor2> -inline RetType UnrollTailLoop<0>::exec(int, RetType returnIfExited, Functor1, Functor2, int) +template <> template <typename RetType, typename Functor1, typename Functor2, typename Number> +inline RetType UnrollTailLoop<0>::exec(Number, RetType returnIfExited, Functor1, Functor2, Number) { return returnIfExited; } |