diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-11-28 10:57:51 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-11-28 16:26:24 +0000 |
commit | ca1f842158419e49b2a010f58e347d7af3b28b93 (patch) | |
tree | e48d8b6f56c9efd364a171bf42e1ed0c2c07b149 /src/corelib/io | |
parent | 88d7c8f963414f4d3ac7a406faddcc074ca6462d (diff) |
QDebug: reduce template bloat
When streaming non-Q_FLAG QFlags, factor the common code
into a helper function only templated on QFlags<T>::Int
and pass what varies as parameters.
Then overload the helper function for the most common int
type (int) as an out-of-line function, implemented via the
primary template to avoid the two going out of sync.
That leaves the primary helper template only for special
cases (such as future extensions).
Change-Id: I70e0001bcfacab9f8765c9b1075fe80b596223f1
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qdebug.cpp | 13 | ||||
-rw-r--r-- | src/corelib/io/qdebug.h | 36 |
2 files changed, 35 insertions, 14 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 002c9bcda2..4f85ceb084 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -867,6 +867,19 @@ QDebugStateSaver::~QDebugStateSaver() d->restoreState(); } +/*! + \internal + + Specialization of the primary template in qdebug.h to out-of-line + the common case of QFlags<T>::Int being int. + + Just call the generic version so the two don't get out of sync. +*/ +void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, int value) +{ + qt_QMetaEnum_flagDebugOperator<int>(debug, sizeofT, value); +} + #ifndef QT_NO_QOBJECT /*! \internal diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index a01dd03a8a..858231e118 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -323,6 +323,27 @@ inline QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache) return debug.maybeSpace(); } +Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, int value); + +template <typename Int> +void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, Int value) +{ + const QDebugStateSaver saver(debug); + debug.resetFormat(); + debug.nospace() << "QFlags(" << hex << showbase; + bool needSeparator = false; + for (uint i = 0; i < sizeofT * 8; ++i) { + if (value & (Int(1) << i)) { + if (needSeparator) + debug << '|'; + else + needSeparator = true; + debug << (Int(1) << i); + } + } + debug << ')'; +} + #if !defined(QT_NO_QOBJECT) && !defined(Q_QDOC) Q_CORE_EXPORT QDebug qt_QMetaEnum_debugOperator(QDebug&, int value, const QMetaObject *meta, const char *name); Q_CORE_EXPORT QDebug qt_QMetaEnum_flagDebugOperator(QDebug &dbg, quint64 value, const QMetaObject *meta, const char *name); @@ -357,20 +378,7 @@ template <class T> inline QDebug qt_QMetaEnum_flagDebugOperator_helper(QDebug debug, const QFlags<T> &flags) #endif { - QDebugStateSaver saver(debug); - debug.resetFormat(); - debug.nospace() << "QFlags(" << hex << showbase; - bool needSeparator = false; - for (uint i = 0; i < sizeof(T) * 8; ++i) { - if (flags.testFlag(T(1 << i))) { - if (needSeparator) - debug << '|'; - else - needSeparator = true; - debug << (typename QFlags<T>::Int(1) << i); - } - } - debug << ')'; + qt_QMetaEnum_flagDebugOperator(debug, sizeof(T), typename QFlags<T>::Int(flags)); return debug; } |