Optimize QTimeZone construction on Android

isTimeZoneIdAvailable() is significantly slower than just trying to
initialize the timezone and see if that worked.

Even in the x86 emulator the difference for this is from 2+ms to no
longer measurable here, on less powerful ARM devices it's even more
extreme. This matters in particular for code creating many QTimeZone
instances, e.g. for calendaring.

Pick-to: 6.7 6.6 6.5
Change-Id: I5f175137b8b71816347a8debb492214427a51104
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Volker Krause 2024-01-05 17:10:41 +01:00
parent 21196d26d8
commit f4e83fccb4

View File

@ -456,8 +456,15 @@ QTimeZone::QTimeZone(const QByteArray &ianaId)
if (!d->isValid()) {
if (ianaId.isEmpty())
d = newBackendTimeZone();
#ifdef Q_OS_ANDROID
// on Android the isTimeZoneIdAvailable() implementation is vastly more
// expensive than just trying to create a timezone
else
d = newBackendTimeZone(ianaId);
#else
else if (global_tz->backend->isTimeZoneIdAvailable(ianaId))
d = newBackendTimeZone(ianaId);
#endif
// else: No such ID, avoid creating a TZ cache entry for it.
}
// Can also handle UTC with arbitrary (valid) offset, but only do so as