diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-01-22 12:23:14 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-02-17 15:04:24 +0000 |
commit | 8f553484fa1d0ef7db026723ef8b1cbe79f85faa (patch) | |
tree | 7244941fc8c5cfe28660d48fae0fba269d026b20 | |
parent | 5b7729ae79cea9c75d297ecfa043ab329f84bc3b (diff) |
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 <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
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 |