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>bb10
parent
a4bec7b388
commit
80bfb8f1ad
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue