From 1d2efe1f27bedcbaa157ef4e82b8eda33dda46ad Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Jan 2015 14:35:25 +0100 Subject: QDateTime: micro-optimize QDebug op<< Instead of constructing a QString that describes the QDateTime instance, stream the constituents of the string into QDebug directly, using op<< for Q_ENUM, now that it's available. Adapt test to new format of enums. Effects on Linux GCC 4.9 stripped release builds: text -1068B data +-0B relocs +-0 Change-Id: I1a5ce28904edd7d0f6c8d982fd41c52e3536e036 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 13 +++++-------- tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp | 5 ++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index eb82113f94..adfcbcecf0 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -5007,26 +5007,23 @@ QDebug operator<<(QDebug dbg, const QTime &time) QDebug operator<<(QDebug dbg, const QDateTime &date) { QDebugStateSaver saver(dbg); - QString spec; + dbg.nospace() << "QDateTime(" << date.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) + << ' ' << date.timeSpec(); switch (date.d->m_spec) { case Qt::UTC: - spec = QStringLiteral(" Qt::UTC"); break; case Qt::OffsetFromUTC: - spec = QString::fromLatin1(" Qt::OffsetFromUTC %1s").arg(date.offsetFromUtc()); + dbg << ' ' << date.offsetFromUtc() << 's'; break; case Qt::TimeZone: #ifndef QT_BOOTSTRAPPED - spec = QStringLiteral(" Qt::TimeZone ") + QString::fromLatin1(date.timeZone().id()); + dbg << ' ' << date.timeZone().id(); break; #endif // QT_BOOTSTRAPPED case Qt::LocalTime: - spec = QStringLiteral(" Qt::LocalTime"); break; } - QString output = date.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) + spec; - dbg.nospace() << "QDateTime(" << output << ')'; - return dbg; + return dbg << ')'; } #endif diff --git a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp index 8938e8bebf..12a67be213 100644 --- a/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp +++ b/tests/auto/corelib/io/qnodebug/tst_qnodebug.cpp @@ -69,9 +69,8 @@ void tst_QNoDebug::noDebugOutput() const void tst_QNoDebug::streaming() const { QDateTime dt(QDate(1,2,3),QTime(4,5,6)); - QString debugString = dt.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) - + QStringLiteral(" Qt::LocalTime"); - QTest::ignoreMessage(QtWarningMsg, qPrintable(QString::fromLatin1("QDateTime(\"%1\")").arg(debugString))); + const QString debugString = dt.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")); + QTest::ignoreMessage(QtWarningMsg, qPrintable(QString::asprintf("QDateTime(\"%1\" Qt::TimeSpec(LocalTime))").arg(debugString))); qWarning() << dt; } -- cgit v1.2.3