Reduce QtCoreLib size by not repeating "UTC" string too often.

It is a minor reduction, in release build it is ~200 bytes

Change-Id: I4f7972c95769f2e0ca1ddc935ff7a0a6b4379e2a
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
This commit is contained in:
Jędrzej Nowacki 2014-05-15 11:32:33 +00:00 committed by Marc Mutz
parent 5026835690
commit ce14208c38
5 changed files with 21 additions and 10 deletions

View File

@ -3194,7 +3194,7 @@ QTimeZone QDateTime::timeZone() const
return d->m_timeZone; return d->m_timeZone;
case Qt::UTC: case Qt::UTC:
if (!d->m_timeZone.isValid()) if (!d->m_timeZone.isValid())
d->m_timeZone = QTimeZone("UTC"); d->m_timeZone = QTimeZone(QTimeZonePrivate::utcQByteArray());
return d->m_timeZone; return d->m_timeZone;
case Qt::TimeZone : case Qt::TimeZone :
return d->m_timeZone; return d->m_timeZone;
@ -3254,9 +3254,9 @@ QString QDateTime::timeZoneAbbreviation() const
{ {
switch (d->m_spec) { switch (d->m_spec) {
case Qt::UTC: case Qt::UTC:
return QStringLiteral("UTC"); return QTimeZonePrivate::utcQString();
case Qt::OffsetFromUTC: case Qt::OffsetFromUTC:
return QLatin1String("UTC") + toOffsetString(Qt::ISODate, d->m_offsetFromUtc); return QTimeZonePrivate::utcQString() + toOffsetString(Qt::ISODate, d->m_offsetFromUtc);
case Qt::TimeZone: case Qt::TimeZone:
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
return d->m_timeZone.d->abbreviation(d->toMSecsSinceEpoch()); return d->m_timeZone.d->abbreviation(d->toMSecsSinceEpoch());

View File

@ -558,8 +558,8 @@ template<> QTimeZonePrivate *QSharedDataPointer<QTimeZonePrivate>::clone()
// Create default UTC time zone // Create default UTC time zone
QUtcTimeZonePrivate::QUtcTimeZonePrivate() QUtcTimeZonePrivate::QUtcTimeZonePrivate()
{ {
const QString name = QStringLiteral("UTC"); const QString name = utcQString();
init(QByteArrayLiteral("UTC"), 0, name, name, QLocale::AnyCountry, name); init(utcQByteArray(), 0, name, name, QLocale::AnyCountry, name);
} }
// Create a named UTC time zone // Create a named UTC time zone
@ -583,7 +583,7 @@ QUtcTimeZonePrivate::QUtcTimeZonePrivate(qint32 offsetSeconds)
QString utcId; QString utcId;
if (offsetSeconds == 0) if (offsetSeconds == 0)
utcId = QStringLiteral("UTC"); utcId = utcQString();
else else
utcId = isoOffsetFormat(offsetSeconds); utcId = isoOffsetFormat(offsetSeconds);
@ -675,7 +675,7 @@ qint32 QUtcTimeZonePrivate::daylightTimeOffset(qint64 atMSecsSinceEpoch) const
QByteArray QUtcTimeZonePrivate::systemTimeZoneId() const QByteArray QUtcTimeZonePrivate::systemTimeZoneId() const
{ {
return QByteArrayLiteral("UTC"); return utcQByteArray();
} }
QSet<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds() const QSet<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds() const

View File

@ -154,6 +154,17 @@ public:
static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId, static QList<QByteArray> windowsIdToIanaIds(const QByteArray &windowsId,
QLocale::Country country); QLocale::Country country);
// returns "UTC" QString and QByteArray
static inline QString utcQString() Q_REQUIRED_RESULT
{
return QStringLiteral("UTC");
}
static inline QByteArray utcQByteArray() Q_REQUIRED_RESULT
{
return QByteArrayLiteral("UTC");
}
protected: protected:
QByteArray m_id; QByteArray m_id;
}; };

View File

@ -958,7 +958,7 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const
// Give up for now and return UTC // Give up for now and return UTC
if (ianaId.isEmpty()) if (ianaId.isEmpty())
ianaId = QByteArrayLiteral("UTC"); ianaId = utcQByteArray();
return ianaId; return ianaId;
} }

View File

@ -249,7 +249,7 @@ static QByteArray windowsSystemZoneId()
} }
// If we can't determine the current ID use UTC // If we can't determine the current ID use UTC
return QByteArrayLiteral("UTC"); return QTimeZonePrivate::utcQByteArray();
} }
static QDate calculateTransitionLocalDate(const SYSTEMTIME &rule, int year) static QDate calculateTransitionLocalDate(const SYSTEMTIME &rule, int year)
@ -635,7 +635,7 @@ QByteArray QWinTimeZonePrivate::systemTimeZoneId() const
ianaId = windowsIdToDefaultIanaId(windowsId); ianaId = windowsIdToDefaultIanaId(windowsId);
// If no global default then probably an unknown Windows ID so return UTC // If no global default then probably an unknown Windows ID so return UTC
if (ianaId.isEmpty()) if (ianaId.isEmpty())
return QByteArrayLiteral("UTC"); return utcQByteArray();
} }
return ianaId; return ianaId;
} }