QDate: optimize QDate::toString()

Instead of using a QString::arg() cascade, which creates tons of
temporaries, use good 'ol sprintf().

Effects on Linux GCC 4.9 stripped release builds:
 text   -216B
 data    +-0B
 relocs  +-0

Change-Id: I6ff551cb9f42e0c05a64f03a8e177fb527915481
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2015-01-22 12:34:44 +01:00
parent 8f553484fa
commit 647ad3fe25

View File

@ -888,9 +888,7 @@ QString QDate::toString(Qt::DateFormat format) const
pd = getDateFromJulianDay(jd); pd = getDateFromJulianDay(jd);
if (pd.year < 0 || pd.year > 9999) if (pd.year < 0 || pd.year > 9999)
return QString(); return QString();
return QString::fromLatin1("%1-%2-%3").arg(pd.year, 4, 10, QLatin1Char('0')) return QString::asprintf("%04d-%02d-%02d", pd.year, pd.month, pd.day);
.arg(pd.month, 2, 10, QLatin1Char('0'))
.arg(pd.day, 2, 10, QLatin1Char('0'));
} }
} }