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>
bb10
Marc Mutz 2015-01-22 12:23:14 +01:00
parent 5b7729ae79
commit 8f553484fa
1 changed files with 6 additions and 10 deletions

View File

@ -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