From 185f9e0758cd7ee649f42b5c788fdfff6031d83c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 5 Nov 2018 13:12:16 -0800 Subject: Merge the qt_memfill{,_template} functions We had two copies of the Duff's Device implementation, one in the .cpp and one in the header. One of the two implementations had a protection against zero counts, the other didn't. So move the .cpp implementation to the header and use it in the functions that were declared there. Fixes: QTBUG-16104 Patch-By: Allan Sandfeld Jensen Change-Id: Iba4b5c183776497d8ee1fffd156456cc3502946e Reviewed-by: Allan Sandfeld Jensen --- src/gui/painting/qdrawhelper.cpp | 43 ++++-------------------------------- src/gui/painting/qdrawhelper_p.h | 47 ++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 62 deletions(-) diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp index c0320f5a70..fdf867ec40 100644 --- a/src/gui/painting/qdrawhelper.cpp +++ b/src/gui/painting/qdrawhelper.cpp @@ -6244,36 +6244,13 @@ DrawHelper qDrawHelper[QImage::NImageFormats] = }, }; -#if defined(Q_CC_MSVC) && !defined(_MIPS_) -template -inline void qt_memfill_template(T *dest, T color, int count) -{ - while (count--) - *dest++ = color; -} - -#else - -template -inline void qt_memfill_template(T *dest, T color, int count) +void qt_memfill64(quint64 *dest, quint64 color, int count) { - int n = (count + 7) / 8; - switch (count & 0x07) - { - case 0: do { *dest++ = color; Q_FALLTHROUGH(); - case 7: *dest++ = color; Q_FALLTHROUGH(); - case 6: *dest++ = color; Q_FALLTHROUGH(); - case 5: *dest++ = color; Q_FALLTHROUGH(); - case 4: *dest++ = color; Q_FALLTHROUGH(); - case 3: *dest++ = color; Q_FALLTHROUGH(); - case 2: *dest++ = color; Q_FALLTHROUGH(); - case 1: *dest++ = color; - } while (--n > 0); - } + qt_memfill_template(dest, color, count); } -template <> -inline void qt_memfill_template(quint16 *dest, quint16 value, int count) +#if !defined(__SSE2__) +void qt_memfill16(quint16 *dest, quint16 value, int count) { if (count < 3) { switch (count) { @@ -6294,18 +6271,6 @@ inline void qt_memfill_template(quint16 *dest, quint16 value, int count) dest[count - 1] = value; } #endif - -void qt_memfill64(quint64 *dest, quint64 color, int count) -{ - qt_memfill_template(dest, color, count); -} - -#if !defined(__SSE2__) -void qt_memfill16(quint16 *dest, quint16 color, int count) -{ - qt_memfill_template(dest, color, count); -} -#endif #if !defined(__SSE2__) && !defined(__ARM_NEON__) && !defined(__MIPS_DSP__) void qt_memfill32(quint32 *dest, quint32 color, int count) { diff --git a/src/gui/painting/qdrawhelper_p.h b/src/gui/painting/qdrawhelper_p.h index 23520ad64b..68003ac321 100644 --- a/src/gui/painting/qdrawhelper_p.h +++ b/src/gui/painting/qdrawhelper_p.h @@ -884,8 +884,30 @@ inline quint24::operator uint() const return data[2] | (data[1] << 8) | (data[0] << 16); } -template static -void qt_memfill(T *dest, T value, int count); +template inline void qt_memfill_template(T *dest, T color, int count) +{ + if (!count) + return; + + qsizetype n = (count + 7) / 8; + switch (count & 0x07) + { + case 0: do { *dest++ = color; Q_FALLTHROUGH(); + case 7: *dest++ = color; Q_FALLTHROUGH(); + case 6: *dest++ = color; Q_FALLTHROUGH(); + case 5: *dest++ = color; Q_FALLTHROUGH(); + case 4: *dest++ = color; Q_FALLTHROUGH(); + case 3: *dest++ = color; Q_FALLTHROUGH(); + case 2: *dest++ = color; Q_FALLTHROUGH(); + case 1: *dest++ = color; + } while (--n > 0); + } +} + +template inline void qt_memfill(T *dest, T value, int count) +{ + qt_memfill_template(dest, value, count); +} template<> inline void qt_memfill(quint64 *dest, quint64 color, int count) { @@ -907,27 +929,6 @@ template<> inline void qt_memfill(quint8 *dest, quint8 color, int count) memset(dest, color, count); } -template -inline void qt_memfill(T *dest, T value, int count) -{ - if (!count) - return; - - int n = (count + 7) / 8; - switch (count & 0x07) - { - case 0: do { *dest++ = value; Q_FALLTHROUGH(); - case 7: *dest++ = value; Q_FALLTHROUGH(); - case 6: *dest++ = value; Q_FALLTHROUGH(); - case 5: *dest++ = value; Q_FALLTHROUGH(); - case 4: *dest++ = value; Q_FALLTHROUGH(); - case 3: *dest++ = value; Q_FALLTHROUGH(); - case 2: *dest++ = value; Q_FALLTHROUGH(); - case 1: *dest++ = value; - } while (--n > 0); - } -} - template static inline void qt_rectfill(T *dest, T value, int x, int y, int width, int height, qsizetype stride) -- cgit v1.2.3