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 <thiago.macieira@intel.com>
(cherry picked from commit 67fb5dcfcd1bac5d5b30723a4ebba84acda58902)
Reviewed-by: Mate Barany <mate.barany@qt.io>
This commit is contained in:
Edward Welbourne 2024-06-04 17:54:05 +02:00
parent f60fd291b5
commit abf8d5a671

View File

@ -613,7 +613,8 @@ QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds() const
return QList<QByteArray>();
}
static QList<QByteArray> selectAvailable(QList<QByteArray>&& desired, const QList<QByteArray>& all)
static QList<QByteArray> selectAvailable(QList<QByteArrayView> &&desired,
const QList<QByteArray> &all)
{
std::sort(desired.begin(), desired.end());
const auto newEnd = std::unique(desired.begin(), desired.end());
@ -628,13 +629,13 @@ static QList<QByteArray> selectAvailable(QList<QByteArray>&& desired, const QLis
QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds(QLocale::Territory territory) const
{
// Default fall-back mode, use the zoneTable to find Region of know Zones
QList<QByteArray> regions;
QList<QByteArrayView> 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<QByteArray> QTimeZonePrivate::availableTimeZoneIds(QLocale::Territory terr
QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const
{
// Default fall-back mode, use the zoneTable to find Offset of know Zones
QList<QByteArray> 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<QByteArrayView> 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());
}
}
}