diff options
Diffstat (limited to 'src/corelib/tools/qtimezoneprivate.cpp')
-rw-r--r-- | src/corelib/tools/qtimezoneprivate.cpp | 86 |
1 files changed, 48 insertions, 38 deletions
diff --git a/src/corelib/tools/qtimezoneprivate.cpp b/src/corelib/tools/qtimezoneprivate.cpp index 4f6067f508..8e6a0a0578 100644 --- a/src/corelib/tools/qtimezoneprivate.cpp +++ b/src/corelib/tools/qtimezoneprivate.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 John Layt <jlayt@kde.org> -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -39,6 +39,8 @@ #include <qdatastream.h> #include <qdebug.h> +#include <algorithm> + QT_BEGIN_NAMESPACE enum { @@ -341,36 +343,38 @@ QByteArray QTimeZonePrivate::systemTimeZoneId() const return QByteArray(); } -QSet<QByteArray> QTimeZonePrivate::availableTimeZoneIds() const +QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds() const { - return QSet<QByteArray>(); + return QList<QByteArray>(); } -QSet<QByteArray> QTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const +QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const { // Default fall-back mode, use the zoneTable to find Region of know Zones - QSet<QByteArray> regionSet; + QList<QByteArray> regions; // First get all Zones in the Zones table belonging to the Region for (int i = 0; i < zoneDataTableSize; ++i) { if (zoneData(i)->country == country) - regionSet += ianaId(zoneData(i)).split(' ').toSet(); + regions += ianaId(zoneData(i)).split(' '); } - // Then select just those that are available - QSet<QByteArray> set; - foreach (const QByteArray &ianaId, availableTimeZoneIds()) { - if (regionSet.contains(ianaId)) - set << ianaId; - } + std::sort(regions.begin(), regions.end()); + regions.erase(std::unique(regions.begin(), regions.end()), regions.end()); - return set; + // Then select just those that are available + const QList<QByteArray> all = availableTimeZoneIds(); + QList<QByteArray> result; + result.reserve(qMin(all.size(), regions.size())); + std::set_intersection(all.begin(), all.end(), regions.cbegin(), regions.cend(), + std::back_inserter(result)); + return result; } -QSet<QByteArray> QTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const +QList<QByteArray> QTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const { // Default fall-back mode, use the zoneTable to find Offset of know Zones - QSet<QByteArray> offsetSet; + QList<QByteArray> offsets; // First get all Zones in the table using the Offset for (int i = 0; i < windowsDataTableSize; ++i) { const QWindowsData *winData = windowsData(i); @@ -378,19 +382,21 @@ QSet<QByteArray> QTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const for (int j = 0; j < zoneDataTableSize; ++j) { const QZoneData *data = zoneData(j); if (data->windowsIdKey == winData->windowsIdKey) - offsetSet += ianaId(data).split(' ').toSet(); + offsets += ianaId(data).split(' '); } } } - // Then select just those that are available - QSet<QByteArray> set; - foreach (const QByteArray &ianaId, availableTimeZoneIds()) { - if (offsetSet.contains(ianaId)) - set << ianaId; - } + std::sort(offsets.begin(), offsets.end()); + offsets.erase(std::unique(offsets.begin(), offsets.end()), offsets.end()); - return set; + // Then select just those that are available + const QList<QByteArray> all = availableTimeZoneIds(); + QList<QByteArray> result; + result.reserve(qMin(all.size(), offsets.size())); + std::set_intersection(all.begin(), all.end(), offsets.cbegin(), offsets.cend(), + std::back_inserter(result)); + return result; } #ifndef QT_NO_DATASTREAM @@ -691,31 +697,35 @@ QByteArray QUtcTimeZonePrivate::systemTimeZoneId() const return utcQByteArray(); } -QSet<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds() const +QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds() const { - QSet<QByteArray> set; + QList<QByteArray> result; for (int i = 0; i < utcDataTableSize; ++i) - set << utcId(utcData(i)); - return set; + result << utcId(utcData(i)); + std::sort(result.begin(), result.end()); // ### or already sorted?? + // ### assuming no duplicates + return result; } -QSet<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const +QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const { // If AnyCountry then is request for all non-region offset codes if (country == QLocale::AnyCountry) return availableTimeZoneIds(); - return QSet<QByteArray>(); + return QList<QByteArray>(); } -QSet<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(qint32 offsetSeconds) const +QList<QByteArray> QUtcTimeZonePrivate::availableTimeZoneIds(qint32 offsetSeconds) const { - QSet<QByteArray> set; + QList<QByteArray> result; for (int i = 0; i < utcDataTableSize; ++i) { const QUtcData *data = utcData(i); if (data->offsetFromUtc == offsetSeconds) - set << utcId(data); + result << utcId(data); } - return set; + std::sort(result.begin(), result.end()); // ### or already sorted?? + // ### assuming no duplicates + return result; } #ifndef QT_NO_DATASTREAM |