Make QMacTimeZonePrivate default constructor more efficient

Inline systemTimeZoneId() in it to save the need for init().
We thus save the lookup by name for a time-zone object, when that
object is what we took the name from anyway.

Do some minor tidy-up in the other constructors and add an assert to
systemTimeZoneId() to match the new one in the default constructor.

Change-Id: Ib70acf31bdb4a4fa1306eebd1fd5f00ad6b89bcc
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Edward Welbourne 2019-11-27 15:25:29 +01:00
parent 9f79ab360f
commit deb166a5ff

View File

@ -60,22 +60,24 @@ QT_BEGIN_NAMESPACE
// Create the system default time zone // Create the system default time zone
QMacTimeZonePrivate::QMacTimeZonePrivate() QMacTimeZonePrivate::QMacTimeZonePrivate()
: m_nstz(0)
{ {
init(systemTimeZoneId()); // Reset the cached system tz then instantiate it:
[NSTimeZone resetSystemTimeZone];
m_nstz = [NSTimeZone.systemTimeZone retain];
Q_ASSERT(m_nstz);
m_id = QString::fromNSString(m_nstz.name).toUtf8();
} }
// Create a named time zone // Create a named time zone
QMacTimeZonePrivate::QMacTimeZonePrivate(const QByteArray &ianaId) QMacTimeZonePrivate::QMacTimeZonePrivate(const QByteArray &ianaId)
: m_nstz(0) : m_nstz(nil)
{ {
init(ianaId); init(ianaId);
} }
QMacTimeZonePrivate::QMacTimeZonePrivate(const QMacTimeZonePrivate &other) QMacTimeZonePrivate::QMacTimeZonePrivate(const QMacTimeZonePrivate &other)
: QTimeZonePrivate(other), m_nstz(0) : QTimeZonePrivate(other), m_nstz([other.m_nstz copy])
{ {
m_nstz = [other.m_nstz copy];
} }
QMacTimeZonePrivate::~QMacTimeZonePrivate() QMacTimeZonePrivate::~QMacTimeZonePrivate()
@ -316,6 +318,7 @@ QByteArray QMacTimeZonePrivate::systemTimeZoneId() const
{ {
// Reset the cached system tz then return the name // Reset the cached system tz then return the name
[NSTimeZone resetSystemTimeZone]; [NSTimeZone resetSystemTimeZone];
Q_ASSERT(NSTimeZone.systemTimeZone);
return QString::fromNSString([[NSTimeZone systemTimeZone] name]).toUtf8(); return QString::fromNSString([[NSTimeZone systemTimeZone] name]).toUtf8();
} }