mirror of https://github.com/qt/qtbase.git
Implement QTZP::isTimeZoneIdAvailable() on Android
The QTZP base implementation of the availability check was to
construct the list of all available IDs, then see whether the given ID
appears in it. This can be very inefficient. The ICU backend has
recently grown a more efficient solution than that, matching the TZ
and Darwin backends. For Android this was still very inefficient, but
its instantiation is cheaper, so simply instantiate and see if the
result is valid. For MS, the backend caches the list of available
zones, so searching the list is a reasonable solution, given the
complexity of its constructor.
Add an implementation for Android and document, in the base-class,
that the fall-back is only suitable for use if the list is cached.
Pick-to: 6.6 6.5
Change-Id: I9dc2ba4be1492ec811c8db6cff9490ac0303115d
Reviewed-by: Volker Krause <vkrause@kde.org>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 7c502391cf
)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
be149bfd82
commit
219fbe7b21
|
@ -465,7 +465,8 @@ QByteArray QTimeZonePrivate::systemTimeZoneId() const
|
|||
|
||||
bool QTimeZonePrivate::isTimeZoneIdAvailable(const QByteArray& ianaId) const
|
||||
{
|
||||
// Fall-back implementation, can be made faster in subclasses
|
||||
// Fall-back implementation, can be made faster in subclasses.
|
||||
// Backends that don't cache the available list SHOULD override this.
|
||||
const QList<QByteArray> tzIds = availableTimeZoneIds();
|
||||
return std::binary_search(tzIds.begin(), tzIds.end(), ianaId);
|
||||
}
|
||||
|
|
|
@ -206,6 +206,12 @@ QByteArray QAndroidTimeZonePrivate::systemTimeZoneId() const
|
|||
return id.toString().toUtf8();
|
||||
}
|
||||
|
||||
bool QAndroidTimeZonePrivate::isTimeZoneIdAvailable(const QByteArray &ianaId) const
|
||||
{
|
||||
QAndroidTimeZonePrivate probe(ianaId);
|
||||
return probe.isValid();
|
||||
}
|
||||
|
||||
QList<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const
|
||||
{
|
||||
QList<QByteArray> availableTimeZoneIdList;
|
||||
|
|
|
@ -463,7 +463,7 @@ public:
|
|||
Data data(qint64 forMSecsSinceEpoch) const override;
|
||||
|
||||
QByteArray systemTimeZoneId() const override;
|
||||
|
||||
bool isTimeZoneIdAvailable(const QByteArray &ianaId) const override;
|
||||
QList<QByteArray> availableTimeZoneIds() const override;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue