summaryrefslogtreecommitdiffstats
path: root/src/corelib/time/qtimezoneprivate_win.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2023-11-14 11:14:38 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2023-11-24 18:09:16 +0100
commitd59e539b3a1252aa22783c4fdf1e22b35e5a4292 (patch)
tree44eb5147e43370e660adc7f250a1a96c53895288 /src/corelib/time/qtimezoneprivate_win.cpp
parent72be53ca28905f49973767677ad18af7c4208740 (diff)
Implement a TODO: cache the list of MS TZ IDs
The MS TZ-backend's lookup of available Windows IDs included a TODO advocating caching the result, since it is unlikely to change at runtime. Given that MS's time_t functions don't believe in times before 1970 and two-digit year parsing (such as the ASN.1 parser does, apparently many times, during SSL handshakes) assumes the 1900s (and certs in use today have mostly been issued this century), SSL involves DTP falling back repeatedly to lookups of local time's offsets from UTC (before it discovers it shouldn't have been using local time anyway) via the system timezone object, this cacheable list can be accessed many times. (A user has reported thousands per SSL socket created.) So let's implement that TODO and trust that updates to the registry's set of available zones aren't a common occurrence at runtime. Pick-to: 6.6 6.5 Change-Id: Iefe235c71da1bf5c3372c52dba89ad0657e06c0b Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/time/qtimezoneprivate_win.cpp')
-rw-r--r--src/corelib/time/qtimezoneprivate_win.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/src/corelib/time/qtimezoneprivate_win.cpp b/src/corelib/time/qtimezoneprivate_win.cpp
index b1abcb7a97..82666407d2 100644
--- a/src/corelib/time/qtimezoneprivate_win.cpp
+++ b/src/corelib/time/qtimezoneprivate_win.cpp
@@ -186,22 +186,24 @@ bool isSameRule(const QWinTimeZonePrivate::QWinTransitionRule &last,
QList<QByteArray> availableWindowsIds()
{
- // TODO Consider caching results in a global static, very unlikely to change.
- QList<QByteArray> list;
- QWinRegistryKey key(HKEY_LOCAL_MACHINE, tzRegPath);
- if (key.isValid()) {
- DWORD idCount = 0;
- if (RegQueryInfoKey(key, 0, 0, 0, &idCount, 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS
- && idCount > 0) {
- for (DWORD i = 0; i < idCount; ++i) {
- DWORD maxLen = MAX_KEY_LENGTH;
- TCHAR buffer[MAX_KEY_LENGTH];
- if (RegEnumKeyEx(key, i, buffer, &maxLen, 0, 0, 0, 0) == ERROR_SUCCESS)
- list.append(QString::fromWCharArray(buffer).toUtf8());
+ static const QList<QByteArray> cache = [] {
+ QList<QByteArray> list;
+ QWinRegistryKey key(HKEY_LOCAL_MACHINE, tzRegPath);
+ if (key.isValid()) {
+ DWORD idCount = 0;
+ if (RegQueryInfoKey(key, 0, 0, 0, &idCount, 0, 0, 0, 0, 0, 0, 0) == ERROR_SUCCESS
+ && idCount > 0) {
+ for (DWORD i = 0; i < idCount; ++i) {
+ DWORD maxLen = MAX_KEY_LENGTH;
+ TCHAR buffer[MAX_KEY_LENGTH];
+ if (RegEnumKeyEx(key, i, buffer, &maxLen, 0, 0, 0, 0) == ERROR_SUCCESS)
+ list.append(QString::fromWCharArray(buffer).toUtf8());
+ }
}
}
- }
- return list;
+ return list;
+ }();
+ return cache;
}
QByteArray windowsSystemZoneId()