QTzTimeZonePrivate: use ctor delegation instead of init()

This makes it obvious that the code in init() is only called from the
constructor and its m_icu handling doesn't need mutex protection (to
be added in a subsequent commit).

Since the input to the ctor is the result of a virtual function,
factor said virtual into a static function and call that instead.

Pick-to: 6.3 6.2 5.15
Change-Id: I7c49f2e865201a2ce2b2d86b19dae29c6d337e0e
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-01-04 17:46:20 +01:00
parent 23aa51991d
commit abe802cd00
2 changed files with 9 additions and 9 deletions

View File

@ -348,7 +348,7 @@ public:
QList<QByteArray> availableTimeZoneIds(QLocale::Territory territory) const override;
private:
void init(const QByteArray &ianaId);
static QByteArray staticSystemTimeZoneId();
QList<QTimeZonePrivate::Data> getPosixTransitions(qint64 msNear) const;
Data dataForTzTransition(QTzTransitionTime tran) const;

View File

@ -719,14 +719,8 @@ static QList<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArray
// Create the system default time zone
QTzTimeZonePrivate::QTzTimeZonePrivate()
: QTzTimeZonePrivate(staticSystemTimeZoneId())
{
init(systemTimeZoneId());
}
// Create a named time zone
QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId)
{
init(ianaId);
}
QTzTimeZonePrivate::~QTzTimeZonePrivate()
@ -953,7 +947,8 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::fetchEntry(const QByteArray &ianaId)
return ret;
}
void QTzTimeZonePrivate::init(const QByteArray &ianaId)
// Create a named time zone
QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId)
{
static QTzTimeZoneCache tzCache;
auto entry = tzCache.fetchEntry(ianaId);
@ -1360,6 +1355,11 @@ private:
}
QByteArray QTzTimeZonePrivate::systemTimeZoneId() const
{
return staticSystemTimeZoneId();
}
QByteArray QTzTimeZonePrivate::staticSystemTimeZoneId()
{
// Check TZ env var first, if not populated try find it
QByteArray ianaId = qgetenv("TZ");