From deb166a5ff0ed3693b7d9a1b6a02b41f3f196b39 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 27 Nov 2019 15:25:29 +0100 Subject: [PATCH] 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 --- src/corelib/time/qtimezoneprivate_mac.mm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/corelib/time/qtimezoneprivate_mac.mm b/src/corelib/time/qtimezoneprivate_mac.mm index 4509e316f9..406ee6445f 100644 --- a/src/corelib/time/qtimezoneprivate_mac.mm +++ b/src/corelib/time/qtimezoneprivate_mac.mm @@ -60,22 +60,24 @@ QT_BEGIN_NAMESPACE // Create the system default time zone 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 QMacTimeZonePrivate::QMacTimeZonePrivate(const QByteArray &ianaId) - : m_nstz(0) + : m_nstz(nil) { init(ianaId); } 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() @@ -316,6 +318,7 @@ QByteArray QMacTimeZonePrivate::systemTimeZoneId() const { // Reset the cached system tz then return the name [NSTimeZone resetSystemTimeZone]; + Q_ASSERT(NSTimeZone.systemTimeZone); return QString::fromNSString([[NSTimeZone systemTimeZone] name]).toUtf8(); }