From 8f553484fa1d0ef7db026723ef8b1cbe79f85faa Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 22 Jan 2015 12:23:14 +0100 Subject: QDateTime: optimize toOffsetString() Instead of using a QString::arg() cascade, which creates tons of temporaries, use good 'ol sprintf(). As a consequence, this function is now inlined into all four callers and the total executable size _still_ goes down: Effects on Linux GCC 4.9 stripped release builds: text -420B data +-0B relocs +-0 Change-Id: I10d6abd94b489db7c2f01dc5424f30a798602522 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index e366717d96..b31eb8c23c 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -228,18 +228,14 @@ static ParsedRfcDateTime rfcDateImpl(const QString &s) #endif // QT_NO_DATESTRING // Return offset in [+-]HH:mm format -// Qt::ISODate puts : between the hours and minutes, but Qt:TextDate does not static QString toOffsetString(Qt::DateFormat format, int offset) { - QString result; - if (format == Qt::TextDate) - result = QStringLiteral("%1%2%3"); - else // Qt::ISODate - result = QStringLiteral("%1%2:%3"); - - return result.arg(offset >= 0 ? QLatin1Char('+') : QLatin1Char('-')) - .arg(qAbs(offset) / SECS_PER_HOUR, 2, 10, QLatin1Char('0')) - .arg((qAbs(offset) / 60) % 60, 2, 10, QLatin1Char('0')); + return QString::asprintf("%c%02d%s%02d", + offset >= 0 ? '+' : '-', + qAbs(offset) / SECS_PER_HOUR, + // Qt::ISODate puts : between the hours and minutes, but Qt:TextDate does not: + format == Qt::TextDate ? "" : ":", + (qAbs(offset) / 60) % 60); } // Parse offset in [+-]HH[[:]mm] format -- cgit v1.2.3