Skip to content

Commit

Permalink
Optimize QTimeZone construction on Android
Browse files Browse the repository at this point in the history
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.5
Change-Id: I5f175137b8b71816347a8debb492214427a51104
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit f4e83fc)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 8762c3b)
  • Loading branch information
vkrause authored and Qt Cherry-pick Bot committed Feb 9, 2024
1 parent 7bdc8d4 commit 2cc0cdb
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/corelib/time/qtimezone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,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
Expand Down

0 comments on commit 2cc0cdb

Please sign in to comment.