From abf8d5a6714d78d30bb0d666adc439fa700644d5 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 4 Jun 2024 17:54:05 +0200 Subject: [PATCH] Use QByteArrayView lists of IANA IDs before working out which we have The QTZP::availableTimeZoneIds() overloads taking a territory or offset to select on were building a list of QBAs, allocating copies of static data to do so, and then taking their intersection with the no-parameter overload. Since the latter is of QBAs and the intersection code used its begin() and end() for the first pair of parameters to std::intersection(), from which the results are drawn, we can use a QBAV list for the second pair of parameters (with whose range the first pair's range is intersected), thanks to QBAV entries in the list being comparable with QBA. This saves allocating copies of the static data, when we can make do with simply building a list of views of that data. Belatedly picking to 6.8 as a prerequisite of a later change. Change-Id: I42de4a91273e23fb394f9ae7a86f7f3fadf95be3 Reviewed-by: Thiago Macieira (cherry picked from commit 67fb5dcfcd1bac5d5b30723a4ebba84acda58902) Reviewed-by: Mate Barany --- src/corelib/time/qtimezoneprivate.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index 5e50ce6dbab..99f443aa0e9 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -613,7 +613,8 @@ QList QTimeZonePrivate::availableTimeZoneIds() const return QList(); } -static QList selectAvailable(QList&& desired, const QList& all) +static QList selectAvailable(QList &&desired, + const QList &all) { std::sort(desired.begin(), desired.end()); const auto newEnd = std::unique(desired.begin(), desired.end()); @@ -628,13 +629,13 @@ static QList selectAvailable(QList&& desired, const QLis QList QTimeZonePrivate::availableTimeZoneIds(QLocale::Territory territory) const { // Default fall-back mode, use the zoneTable to find Region of know Zones - QList regions; + QList regions; // First get all Zones in the Zones table belonging to the Region for (const ZoneData &data : zoneDataTable) { if (data.territory == territory) { for (auto l1 : data.ids()) - regions << QByteArray(l1.data(), l1.size()); + regions << QByteArrayView(l1.data(), l1.size()); } } return selectAvailable(std::move(regions), availableTimeZoneIds()); @@ -642,16 +643,16 @@ QList QTimeZonePrivate::availableTimeZoneIds(QLocale::Territory terr QList QTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const { - // Default fall-back mode, use the zoneTable to find Offset of know Zones - QList offsets; - // First get all Zones in the table using the Offset + // Default fall-back mode: use the zoneTable to find offsets of know zones. + QList offsets; + // First get all Zones in the table using the given offset: for (const WindowsData &winData : windowsDataTable) { if (winData.offsetFromUtc == offsetFromUtc) { for (auto data = zoneStartForWindowsId(winData.windowsIdKey); data != std::end(zoneDataTable) && data->windowsIdKey == winData.windowsIdKey; ++data) { for (auto l1 : data->ids()) - offsets << QByteArray(l1.data(), l1.size()); + offsets << QByteArrayView(l1.data(), l1.size()); } } }