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 <thiago.macieira@intel.com>
This commit is contained in:
parent
85ecc44eee
commit
1d2efe1f27
@ -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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user