summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2015-02-23 11:24:04 +0100
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2015-02-23 11:24:07 +0100
commitd34353a065c443aac20376cbd88323480d769183 (patch)
treeda5d86b51c2cf7023356551c4c980849b35bab14 /src/corelib/tools
parent4e40b1952695f0b1086ef7b88e8514bd18cf96bf (diff)
parent571908f7fc8f5e4ef9a4dfd90102566f6f0fcad2 (diff)
Merge dev into 5.5
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qbytearray_mac.mm2
-rw-r--r--src/corelib/tools/qbytearraylist.cpp2
-rw-r--r--src/corelib/tools/qbytearraylist.h2
-rw-r--r--src/corelib/tools/qdatetime.cpp222
-rw-r--r--src/corelib/tools/qdatetime.h54
-rw-r--r--src/corelib/tools/qdatetime_mac.mm2
-rw-r--r--src/corelib/tools/qdatetime_p.h32
-rw-r--r--src/corelib/tools/qlist.h70
-rw-r--r--src/corelib/tools/qlocale_mac.mm2
-rw-r--r--src/corelib/tools/qpair.h15
-rw-r--r--src/corelib/tools/qstring_mac.mm2
-rw-r--r--src/corelib/tools/qtimezone.cpp42
-rw-r--r--src/corelib/tools/qtimezoneprivate.cpp74
-rw-r--r--src/corelib/tools/qtimezoneprivate_android.cpp6
-rw-r--r--src/corelib/tools/qtimezoneprivate_icu.cpp37
-rw-r--r--src/corelib/tools/qtimezoneprivate_mac.mm13
-rw-r--r--src/corelib/tools/qtimezoneprivate_p.h28
-rw-r--r--src/corelib/tools/qtimezoneprivate_tz.cpp16
-rw-r--r--src/corelib/tools/qtimezoneprivate_win.cpp12
-rw-r--r--src/corelib/tools/qversionnumber.cpp2
-rw-r--r--src/corelib/tools/qversionnumber_p.h2
21 files changed, 348 insertions, 289 deletions
diff --git a/src/corelib/tools/qbytearray_mac.mm b/src/corelib/tools/qbytearray_mac.mm
index e05319f47f..b90c2de836 100644
--- a/src/corelib/tools/qbytearray_mac.mm
+++ b/src/corelib/tools/qbytearray_mac.mm
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2014 Samuel Gaist <samuel.gaist@edeltech.ch>
-** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
+** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/tools/qbytearraylist.cpp b/src/corelib/tools/qbytearraylist.cpp
index 79c2f25868..6a2fa534a5 100644
--- a/src/corelib/tools/qbytearraylist.cpp
+++ b/src/corelib/tools/qbytearraylist.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
+** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2014 by Southwest Research Institute (R)
** Contact: http://www.qt.io/licensing/
**
diff --git a/src/corelib/tools/qbytearraylist.h b/src/corelib/tools/qbytearraylist.h
index 822d53f0f0..9cd241a87b 100644
--- a/src/corelib/tools/qbytearraylist.h
+++ b/src/corelib/tools/qbytearraylist.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
+** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2014 by Southwest Research Institute (R)
** Contact: http://www.qt.io/licensing/
**
diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp
index adfcbcecf0..eeefea8137 100644
--- a/src/corelib/tools/qdatetime.cpp
+++ b/src/corelib/tools/qdatetime.cpp
@@ -117,7 +117,12 @@ static inline qint64 julianDayFromDate(int year, int month, int day)
return day + floordiv(153 * m + 2, 5) + 365 * y + floordiv(y, 4) - floordiv(y, 100) + floordiv(y, 400) - 32045;
}
-static void getDateFromJulianDay(qint64 julianDay, int *yearp, int *monthp, int *dayp)
+struct ParsedDate
+{
+ int year, month, day;
+};
+
+static ParsedDate getDateFromJulianDay(qint64 julianDay)
{
/*
* Math from The Calendar FAQ at http://www.tondering.dk/claus/cal/julperiod.php
@@ -140,12 +145,8 @@ static void getDateFromJulianDay(qint64 julianDay, int *yearp, int *monthp, int
if (year <= 0)
--year ;
- if (yearp)
- *yearp = year;
- if (monthp)
- *monthp = month;
- if (dayp)
- *dayp = day;
+ const ParsedDate result = { year, month, day };
+ return result;
}
/*****************************************************************************
@@ -186,82 +187,55 @@ static int fromShortMonthName(const QStringRef &monthName)
#endif // QT_NO_TEXTDATE
#ifndef QT_NO_DATESTRING
-static void rfcDateImpl(const QString &s, QDate *dd = 0, QTime *dt = 0, int *utcOffset = 0)
-{
- int day = -1;
- int month = -1;
- int year = -1;
- int hour = -1;
- int min = -1;
- int sec = -1;
- int hourOffset = 0;
- int minOffset = 0;
- bool positiveOffset = false;
+struct ParsedRfcDateTime {
+ QDate date;
+ QTime time;
+ int utcOffset;
+};
+
+static ParsedRfcDateTime rfcDateImpl(const QString &s)
+{
+ ParsedRfcDateTime result;
// Matches "Wdy, DD Mon YYYY HH:mm:ss ±hhmm" (Wdy, being optional)
QRegExp rex(QStringLiteral("^(?:[A-Z][a-z]+,)?[ \\t]*(\\d{1,2})[ \\t]+([A-Z][a-z]+)[ \\t]+(\\d\\d\\d\\d)(?:[ \\t]+(\\d\\d):(\\d\\d)(?::(\\d\\d))?)?[ \\t]*(?:([+-])(\\d\\d)(\\d\\d))?"));
if (s.indexOf(rex) == 0) {
- if (dd) {
- day = rex.cap(1).toInt();
- month = qt_monthNumberFromShortName(rex.cap(2));
- year = rex.cap(3).toInt();
- }
- if (dt) {
- if (!rex.cap(4).isEmpty()) {
- hour = rex.cap(4).toInt();
- min = rex.cap(5).toInt();
- sec = rex.cap(6).toInt();
- }
- positiveOffset = (rex.cap(7) == QLatin1String("+"));
- hourOffset = rex.cap(8).toInt();
- minOffset = rex.cap(9).toInt();
- }
- if (utcOffset)
- *utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60));
+ const QStringList cap = rex.capturedTexts();
+ result.date = QDate(cap[3].toInt(), qt_monthNumberFromShortName(cap[2]), cap[1].toInt());
+ if (!cap[4].isEmpty())
+ result.time = QTime(cap[4].toInt(), cap[5].toInt(), cap[6].toInt());
+ const bool positiveOffset = (cap[7] == QLatin1String("+"));
+ const int hourOffset = cap[8].toInt();
+ const int minOffset = cap[9].toInt();
+ result.utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60));
} else {
// Matches "Wdy Mon DD HH:mm:ss YYYY"
QRegExp rex(QStringLiteral("^[A-Z][a-z]+[ \\t]+([A-Z][a-z]+)[ \\t]+(\\d\\d)(?:[ \\t]+(\\d\\d):(\\d\\d):(\\d\\d))?[ \\t]+(\\d\\d\\d\\d)[ \\t]*(?:([+-])(\\d\\d)(\\d\\d))?"));
if (s.indexOf(rex) == 0) {
- if (dd) {
- month = qt_monthNumberFromShortName(rex.cap(1));
- day = rex.cap(2).toInt();
- year = rex.cap(6).toInt();
- }
- if (dt) {
- if (!rex.cap(3).isEmpty()) {
- hour = rex.cap(3).toInt();
- min = rex.cap(4).toInt();
- sec = rex.cap(5).toInt();
- }
- positiveOffset = (rex.cap(7) == QLatin1String("+"));
- hourOffset = rex.cap(8).toInt();
- minOffset = rex.cap(9).toInt();
- }
- if (utcOffset)
- *utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60));
+ const QStringList cap = rex.capturedTexts();
+ result.date = QDate(cap[6].toInt(), qt_monthNumberFromShortName(cap[1]), cap[2].toInt());
+ if (!cap[3].isEmpty())
+ result.time = QTime(cap[3].toInt(), cap[4].toInt(), cap[5].toInt());
+ const bool positiveOffset = (cap[7] == QLatin1String("+"));
+ const int hourOffset = cap[8].toInt();
+ const int minOffset = cap[9].toInt();
+ result.utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60));
}
}
- if (dd)
- *dd = QDate(year, month, day);
- if (dt)
- *dt = QTime(hour, min, sec);
+ return result;
}
#endif // QT_NO_DATESTRING
// Return offset in [+-]HH:mm format
-// Qt::ISODate puts : between the hours and minutes, but Qt:TextDate does not
static QString toOffsetString(Qt::DateFormat format, int offset)
{
- QString result;
- if (format == Qt::TextDate)
- result = QStringLiteral("%1%2%3");
- else // Qt::ISODate
- result = QStringLiteral("%1%2:%3");
-
- return result.arg(offset >= 0 ? QLatin1Char('+') : QLatin1Char('-'))
- .arg(qAbs(offset) / SECS_PER_HOUR, 2, 10, QLatin1Char('0'))
- .arg((qAbs(offset) / 60) % 60, 2, 10, QLatin1Char('0'));
+ return QString::asprintf("%c%02d%s%02d",
+ offset >= 0 ? '+' : '-',
+ qAbs(offset) / SECS_PER_HOUR,
+ // Qt::ISODate puts : between the hours and minutes, but Qt:TextDate does not:
+ format == Qt::TextDate ? "" : ":",
+ (qAbs(offset) / 60) % 60);
}
// Parse offset in [+-]HH[[:]mm] format
@@ -449,9 +423,7 @@ int QDate::year() const
if (isNull())
return 0;
- int y;
- getDateFromJulianDay(jd, &y, 0, 0);
- return y;
+ return getDateFromJulianDay(jd).year;
}
/*!
@@ -483,9 +455,7 @@ int QDate::month() const
if (isNull())
return 0;
- int m;
- getDateFromJulianDay(jd, 0, &m, 0);
- return m;
+ return getDateFromJulianDay(jd).month;
}
/*!
@@ -501,9 +471,7 @@ int QDate::day() const
if (isNull())
return 0;
- int d;
- getDateFromJulianDay(jd, 0, 0, &d);
- return d;
+ return getDateFromJulianDay(jd).day;
}
/*!
@@ -555,12 +523,11 @@ int QDate::daysInMonth() const
if (isNull())
return 0;
- int y, m;
- getDateFromJulianDay(jd, &y, &m, 0);
- if (m == 2 && isLeapYear(y))
+ const ParsedDate pd = getDateFromJulianDay(jd);
+ if (pd.month == 2 && isLeapYear(pd.year))
return 29;
else
- return monthDays[m];
+ return monthDays[pd.month];
}
/*!
@@ -576,9 +543,7 @@ int QDate::daysInYear() const
if (isNull())
return 0;
- int y;
- getDateFromJulianDay(jd, &y, 0, 0);
- return isLeapYear(y) ? 366 : 365;
+ return isLeapYear(getDateFromJulianDay(jd).year) ? 366 : 365;
}
/*!
@@ -895,7 +860,7 @@ QString QDate::toString(Qt::DateFormat format) const
if (!isValid())
return QString();
- int y, m, d;
+ ParsedDate pd;
switch (format) {
case Qt::SystemLocaleDate:
@@ -913,19 +878,17 @@ QString QDate::toString(Qt::DateFormat format) const
default:
#ifndef QT_NO_TEXTDATE
case Qt::TextDate:
- getDateFromJulianDay(jd, &y, &m, &d);
+ pd = getDateFromJulianDay(jd);
return QString::fromLatin1("%1 %2 %3 %4").arg(shortDayName(dayOfWeek()))
- .arg(shortMonthName(m))
- .arg(d)
- .arg(y);
+ .arg(shortMonthName(pd.month))
+ .arg(pd.day)
+ .arg(pd.year);
#endif
case Qt::ISODate:
- getDateFromJulianDay(jd, &y, &m, &d);
- if (y < 0 || y > 9999)
+ pd = getDateFromJulianDay(jd);
+ if (pd.year < 0 || pd.year > 9999)
return QString();
- return QString::fromLatin1("%1-%2-%3").arg(y, 4, 10, QLatin1Char('0'))
- .arg(m, 2, 10, QLatin1Char('0'))
- .arg(d, 2, 10, QLatin1Char('0'));
+ return QString::asprintf("%04d-%02d-%02d", pd.year, pd.month, pd.day);
}
}
@@ -1031,16 +994,16 @@ bool QDate::setDate(int year, int month, int day)
*/
void QDate::getDate(int *year, int *month, int *day)
{
- if (isValid()) {
- getDateFromJulianDay(jd, year, month, day);
- } else {
- if (year)
- *year = 0;
- if (month)
- *month = 0;
- if (day)
- *day = 0;
- }
+ ParsedDate pd = { 0, 0, 0 };
+ if (isValid())
+ pd = getDateFromJulianDay(jd);
+
+ if (year)
+ *year = pd.year;
+ if (month)
+ *month = pd.month;
+ if (day)
+ *day = pd.day;
}
/*!
@@ -1082,7 +1045,12 @@ QDate QDate::addMonths(int nmonths) const
return *this;
int old_y, y, m, d;
- getDateFromJulianDay(jd, &y, &m, &d);
+ {
+ const ParsedDate pd = getDateFromJulianDay(jd);
+ y = pd.year;
+ m = pd.month;
+ d = pd.day;
+ }
old_y = y;
bool increasing = nmonths > 0;
@@ -1140,19 +1108,18 @@ QDate QDate::addYears(int nyears) const
if (!isValid())
return QDate();
- int y, m, d;
- getDateFromJulianDay(jd, &y, &m, &d);
+ ParsedDate pd = getDateFromJulianDay(jd);
- int old_y = y;
- y += nyears;
+ int old_y = pd.year;
+ pd.year += nyears;
// was there a sign change?
- if ((old_y > 0 && y <= 0) ||
- (old_y < 0 && y >= 0))
+ if ((old_y > 0 && pd.year <= 0) ||
+ (old_y < 0 && pd.year >= 0))
// yes, adjust the date by +1 or -1 years
- y += nyears > 0 ? +1 : -1;
+ pd.year += nyears > 0 ? +1 : -1;
- return fixedDate(y, m, d);
+ return fixedDate(pd.year, pd.month, pd.day);
}
/*!
@@ -1255,11 +1222,8 @@ QDate QDate::fromString(const QString& string, Qt::DateFormat format)
return QLocale().toDate(string, QLocale::ShortFormat);
case Qt::DefaultLocaleLongDate:
return QLocale().toDate(string, QLocale::LongFormat);
- case Qt::RFC2822Date: {
- QDate date;
- rfcDateImpl(string, &date);
- return date;
- }
+ case Qt::RFC2822Date:
+ return rfcDateImpl(string).date;
default:
#ifndef QT_NO_TEXTDATE
case Qt::TextDate: {
@@ -2003,11 +1967,8 @@ QTime QTime::fromString(const QString& string, Qt::DateFormat format)
return QLocale().toTime(string, QLocale::ShortFormat);
case Qt::DefaultLocaleLongDate:
return QLocale().toTime(string, QLocale::LongFormat);
- case Qt::RFC2822Date: {
- QTime time;
- rfcDateImpl(string, 0, &time);
- return time;
- }
+ case Qt::RFC2822Date:
+ return rfcDateImpl(string).time;
case Qt::ISODate:
case Qt::TextDate:
default:
@@ -4417,16 +4378,13 @@ QDateTime QDateTime::fromString(const QString& string, Qt::DateFormat format)
case Qt::DefaultLocaleLongDate:
return QLocale().toDateTime(string, QLocale::LongFormat);
case Qt::RFC2822Date: {
- QDate date;
- QTime time;
- int utcOffset = 0;
- rfcDateImpl(string, &date, &time, &utcOffset);
+ const ParsedRfcDateTime rfc = rfcDateImpl(string);
- if (!date.isValid() || !time.isValid())
+ if (!rfc.date.isValid() || !rfc.time.isValid())
return QDateTime();
- QDateTime dateTime(date, time, Qt::UTC);
- dateTime.setOffsetFromUtc(utcOffset);
+ QDateTime dateTime(rfc.date, rfc.time, Qt::UTC);
+ dateTime.setOffsetFromUtc(rfc.utcOffset);
return dateTime;
}
case Qt::ISODate: {
@@ -5007,9 +4965,11 @@ QDebug operator<<(QDebug dbg, const QTime &time)
QDebug operator<<(QDebug dbg, const QDateTime &date)
{
QDebugStateSaver saver(dbg);
- dbg.nospace() << "QDateTime(" << date.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t"))
- << ' ' << date.timeSpec();
- switch (date.d->m_spec) {
+ const Qt::TimeSpec ts = date.timeSpec();
+ dbg.nospace() << "QDateTime(";
+ dbg.noquote() << date.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t"))
+ << ' ' << ts;
+ switch (ts) {
case Qt::UTC:
break;
case Qt::OffsetFromUTC:
diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h
index 3affc7e9aa..784aced71a 100644
--- a/src/corelib/tools/qdatetime.h
+++ b/src/corelib/tools/qdatetime.h
@@ -59,13 +59,13 @@ public:
StandaloneFormat
};
private:
- QDate(qint64 julianDay) : jd(julianDay) {}
+ Q_DECL_CONSTEXPR QDate(qint64 julianDay) : jd(julianDay) {}
public:
- QDate() { jd = nullJd(); }
+ Q_DECL_CONSTEXPR QDate() : jd(nullJd()) {}
QDate(int y, int m, int d);
- bool isNull() const { return !isValid(); }
- bool isValid() const { return jd >= minJd() && jd <= maxJd(); }
+ Q_DECL_CONSTEXPR bool isNull() const { return !isValid(); }
+ Q_DECL_CONSTEXPR bool isValid() const { return jd >= minJd() && jd <= maxJd(); }
int year() const;
int month() const;
@@ -100,12 +100,12 @@ QT_DEPRECATED inline bool setYMD(int y, int m, int d)
QDate addYears(int years) const Q_REQUIRED_RESULT;
qint64 daysTo(const QDate &) const;
- bool operator==(const QDate &other) const { return jd == other.jd; }
- bool operator!=(const QDate &other) const { return jd != other.jd; }
- bool operator<(const QDate &other) const { return jd < other.jd; }
- bool operator<=(const QDate &other) const { return jd <= other.jd; }
- bool operator>(const QDate &other) const { return jd > other.jd; }
- bool operator>=(const QDate &other) const { return jd >= other.jd; }
+ Q_DECL_CONSTEXPR bool operator==(const QDate &other) const { return jd == other.jd; }
+ Q_DECL_CONSTEXPR bool operator!=(const QDate &other) const { return jd != other.jd; }
+ Q_DECL_CONSTEXPR bool operator< (const QDate &other) const { return jd < other.jd; }
+ Q_DECL_CONSTEXPR bool operator<=(const QDate &other) const { return jd <= other.jd; }
+ Q_DECL_CONSTEXPR bool operator> (const QDate &other) const { return jd > other.jd; }
+ Q_DECL_CONSTEXPR bool operator>=(const QDate &other) const { return jd >= other.jd; }
static QDate currentDate();
#ifndef QT_NO_DATESTRING
@@ -115,15 +115,15 @@ QT_DEPRECATED inline bool setYMD(int y, int m, int d)
static bool isValid(int y, int m, int d);
static bool isLeapYear(int year);
- static inline QDate fromJulianDay(qint64 jd)
+ static Q_DECL_CONSTEXPR inline QDate fromJulianDay(qint64 jd)
{ return jd >= minJd() && jd <= maxJd() ? QDate(jd) : QDate() ; }
- inline qint64 toJulianDay() const { return jd; }
+ Q_DECL_CONSTEXPR inline qint64 toJulianDay() const { return jd; }
private:
// using extra parentheses around min to avoid expanding it if it is a macro
- static inline qint64 nullJd() { return (std::numeric_limits<qint64>::min)(); }
- static inline qint64 minJd() { return Q_INT64_C(-784350574879); }
- static inline qint64 maxJd() { return Q_INT64_C( 784354017364); }
+ static Q_DECL_CONSTEXPR inline qint64 nullJd() { return (std::numeric_limits<qint64>::min)(); }
+ static Q_DECL_CONSTEXPR inline qint64 minJd() { return Q_INT64_C(-784350574879); }
+ static Q_DECL_CONSTEXPR inline qint64 maxJd() { return Q_INT64_C( 784354017364); }
qint64 jd;
@@ -138,20 +138,20 @@ Q_DECLARE_TYPEINFO(QDate, Q_MOVABLE_TYPE);
class Q_CORE_EXPORT QTime
{
- QTime(int ms) : mds(ms)
+ Q_DECL_CONSTEXPR QTime(int ms) : mds(ms)
#if defined(Q_OS_WINCE)
, startTick(NullTime)
#endif
{}
public:
- QTime(): mds(NullTime)
+ Q_DECL_CONSTEXPR QTime(): mds(NullTime)
#if defined(Q_OS_WINCE)
, startTick(NullTime)
#endif
{}
QTime(int h, int m, int s = 0, int ms = 0);
- bool isNull() const { return mds == NullTime; }
+ Q_DECL_CONSTEXPR bool isNull() const { return mds == NullTime; }
bool isValid() const;
int hour() const;
@@ -169,15 +169,15 @@ public:
QTime addMSecs(int ms) const Q_REQUIRED_RESULT;
int msecsTo(const QTime &) const;
- bool operator==(const QTime &other) const { return mds == other.mds; }
- bool operator!=(const QTime &other) const { return mds != other.mds; }
- bool operator<(const QTime &other) const { return mds < other.mds; }
- bool operator<=(const QTime &other) const { return mds <= other.mds; }
- bool operator>(const QTime &other) const { return mds > other.mds; }
- bool operator>=(const QTime &other) const { return mds >= other.mds; }
+ Q_DECL_CONSTEXPR bool operator==(const QTime &other) const { return mds == other.mds; }
+ Q_DECL_CONSTEXPR bool operator!=(const QTime &other) const { return mds != other.mds; }
+ Q_DECL_CONSTEXPR bool operator< (const QTime &other) const { return mds < other.mds; }
+ Q_DECL_CONSTEXPR bool operator<=(const QTime &other) const { return mds <= other.mds; }
+ Q_DECL_CONSTEXPR bool operator> (const QTime &other) const { return mds > other.mds; }
+ Q_DECL_CONSTEXPR bool operator>=(const QTime &other) const { return mds >= other.mds; }
- static inline QTime fromMSecsSinceStartOfDay(int msecs) { return QTime(msecs); }
- inline int msecsSinceStartOfDay() const { return mds == NullTime ? 0 : mds; }
+ static Q_DECL_CONSTEXPR inline QTime fromMSecsSinceStartOfDay(int msecs) { return QTime(msecs); }
+ Q_DECL_CONSTEXPR inline int msecsSinceStartOfDay() const { return mds == NullTime ? 0 : mds; }
static QTime currentTime();
#ifndef QT_NO_DATESTRING
@@ -191,7 +191,7 @@ public:
int elapsed() const;
private:
enum TimeFlag { NullTime = -1 };
- inline int ds() const { return mds == -1 ? 0 : mds; }
+ Q_DECL_CONSTEXPR inline int ds() const { return mds == -1 ? 0 : mds; }
int mds;
#if defined(Q_OS_WINCE)
int startTick;
diff --git a/src/corelib/tools/qdatetime_mac.mm b/src/corelib/tools/qdatetime_mac.mm
index c5fd7a0142..c87fc3d9ca 100644
--- a/src/corelib/tools/qdatetime_mac.mm
+++ b/src/corelib/tools/qdatetime_mac.mm
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
+** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2014 Petroules Corporation.
** Contact: http://www.qt.io/licensing/
**
diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h
index d703442963..a139390a9d 100644
--- a/src/corelib/tools/qdatetime_p.h
+++ b/src/corelib/tools/qdatetime_p.h
@@ -101,16 +101,6 @@ public:
QDateTimePrivate(const QDate &toDate, const QTime &toTime, const QTimeZone & timeZone);
#endif // QT_BOOTSTRAPPED
- QDateTimePrivate(const QDateTimePrivate &other) : QSharedData(other),
- m_msecs(other.m_msecs),
- m_spec(other.m_spec),
- m_offsetFromUtc(other.m_offsetFromUtc),
-#ifndef QT_BOOTSTRAPPED
- m_timeZone(other.m_timeZone),
-#endif // QT_BOOTSTRAPPED
- m_status(other.m_status)
- {}
-
// ### XXX: when the tooling situation improves, look at fixing the padding.
// 4 bytes padding
@@ -136,17 +126,17 @@ public:
void refreshDateTime();
// Get/set date and time status
- inline bool isNullDate() const { return (m_status & NullDate) == NullDate; }
- inline bool isNullTime() const { return (m_status & NullTime) == NullTime; }
- inline bool isValidDate() const { return (m_status & ValidDate) == ValidDate; }
- inline bool isValidTime() const { return (m_status & ValidTime) == ValidTime; }
- inline bool isValidDateTime() const { return (m_status & ValidDateTime) == ValidDateTime; }
- inline void setValidDateTime() { m_status = m_status | ValidDateTime; }
- inline void clearValidDateTime() { m_status = m_status & ~ValidDateTime; }
- inline bool isTimeZoneCached() const { return (m_status & TimeZoneCached) == TimeZoneCached; }
- inline void setTimeZoneCached() { m_status = m_status | TimeZoneCached; }
- inline void clearTimeZoneCached() { m_status = m_status & ~TimeZoneCached; }
- inline void clearSetToDaylightStatus() { m_status = m_status & ~SetToStandardTime & ~SetToDaylightTime; }
+ inline bool isNullDate() const { return m_status & NullDate; }
+ inline bool isNullTime() const { return m_status & NullTime; }
+ inline bool isValidDate() const { return m_status & ValidDate; }
+ inline bool isValidTime() const { return m_status & ValidTime; }
+ inline bool isValidDateTime() const { return m_status & ValidDateTime; }
+ inline void setValidDateTime() { m_status |= ValidDateTime; }
+ inline void clearValidDateTime() { m_status &= ~ValidDateTime; }
+ inline bool isTimeZoneCached() const { return m_status & TimeZoneCached; }
+ inline void setTimeZoneCached() { m_status |= TimeZoneCached; }
+ inline void clearTimeZoneCached() { m_status &= ~TimeZoneCached; }
+ inline void clearSetToDaylightStatus() { m_status &= ~(SetToStandardTime | SetToDaylightTime); }
#ifndef QT_BOOTSTRAPPED
static qint64 zoneMSecsToEpochMSecs(qint64 msecs, const QTimeZone &zone,
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 023dafb223..57e67d52d7 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -66,6 +66,14 @@ template <typename T> struct QListSpecialMethods { };
template <> struct QListSpecialMethods<QByteArray>;
struct Q_CORE_EXPORT QListData {
+ // tags for tag-dispatching of QList implementations,
+ // based on QList's three different memory layouts:
+ struct NotArrayCompatibleLayout {};
+ struct NotIndirectLayout {};
+ struct ArrayCompatibleLayout : NotIndirectLayout {}; // data laid out like a C array
+ struct InlineWithPaddingLayout : NotArrayCompatibleLayout, NotIndirectLayout {}; // data laid out like a C array with padding
+ struct IndirectLayout : NotArrayCompatibleLayout {}; // data allocated on the heap
+
struct Data {
QtPrivate::RefCount ref;
int alloc, begin, end;
@@ -99,6 +107,17 @@ struct Q_CORE_EXPORT QListData {
template <typename T>
class QList : public QListSpecialMethods<T>
{
+public:
+ struct MemoryLayout
+ : QtPrivate::if_<
+ QTypeInfo<T>::isStatic || QTypeInfo<T>::isLarge,
+ QListData::IndirectLayout,
+ typename QtPrivate::if_<
+ sizeof(T) == sizeof(void*),
+ QListData::ArrayCompatibleLayout,
+ QListData::InlineWithPaddingLayout
+ >::type>::type {};
+private:
struct Node { void *v;
#if defined(Q_CC_BOR)
Q_INLINE_TEMPLATE T &t();
@@ -358,6 +377,14 @@ private:
{
return (constBegin().i <= i.i) && (i.i <= constEnd().i);
}
+
+private:
+ inline bool op_eq_impl(const QList &other, QListData::NotArrayCompatibleLayout) const;
+ inline bool op_eq_impl(const QList &other, QListData::ArrayCompatibleLayout) const;
+ inline bool contains_impl(const T &, QListData::NotArrayCompatibleLayout) const;
+ inline bool contains_impl(const T &, QListData::ArrayCompatibleLayout) const;
+ inline int count_impl(const T &, QListData::NotArrayCompatibleLayout) const;
+ inline int count_impl(const T &, QListData::ArrayCompatibleLayout) const;
};
#if defined(Q_CC_BOR)
@@ -771,6 +798,12 @@ Q_OUTOFLINE_TEMPLATE bool QList<T>::operator==(const QList<T> &l) const
return true;
if (p.size() != l.p.size())
return false;
+ return this->op_eq_impl(l, MemoryLayout());
+}
+
+template <typename T>
+inline bool QList<T>::op_eq_impl(const QList &l, QListData::NotArrayCompatibleLayout) const
+{
Node *i = reinterpret_cast<Node *>(p.begin());
Node *e = reinterpret_cast<Node *>(p.end());
Node *li = reinterpret_cast<Node *>(l.p.begin());
@@ -782,6 +815,15 @@ Q_OUTOFLINE_TEMPLATE bool QList<T>::operator==(const QList<T> &l) const
}
template <typename T>
+inline bool QList<T>::op_eq_impl(const QList &l, QListData::ArrayCompatibleLayout) const
+{
+ const T *lb = reinterpret_cast<const T*>(l.p.begin());
+ const T *b = reinterpret_cast<const T*>(p.begin());
+ const T *e = reinterpret_cast<const T*>(p.end());
+ return std::equal(b, e, lb);
+}
+
+template <typename T>
Q_OUTOFLINE_TEMPLATE void QList<T>::dealloc(QListData::Data *data)
{
node_destruct(reinterpret_cast<Node *>(data->array + data->begin),
@@ -922,6 +964,12 @@ Q_OUTOFLINE_TEMPLATE int QList<T>::lastIndexOf(const T &t, int from) const
template <typename T>
Q_OUTOFLINE_TEMPLATE bool QList<T>::contains(const T &t) const
{
+ return contains_impl(t, MemoryLayout());
+}
+
+template <typename T>
+inline bool QList<T>::contains_impl(const T &t, QListData::NotArrayCompatibleLayout) const
+{
Node *e = reinterpret_cast<Node *>(p.end());
Node *i = reinterpret_cast<Node *>(p.begin());
for (; i != e; ++i)
@@ -931,8 +979,22 @@ Q_OUTOFLINE_TEMPLATE bool QList<T>::contains(const T &t) const
}
template <typename T>
+inline bool QList<T>::contains_impl(const T &t, QListData::ArrayCompatibleLayout) const
+{
+ const T *b = reinterpret_cast<const T*>(p.begin());
+ const T *e = reinterpret_cast<const T*>(p.end());
+ return std::find(b, e, t) != e;
+}
+
+template <typename T>
Q_OUTOFLINE_TEMPLATE int QList<T>::count(const T &t) const
{
+ return this->count_impl(t, MemoryLayout());
+}
+
+template <typename T>
+inline int QList<T>::count_impl(const T &t, QListData::NotArrayCompatibleLayout) const
+{
int c = 0;
Node *e = reinterpret_cast<Node *>(p.end());
Node *i = reinterpret_cast<Node *>(p.begin());
@@ -942,6 +1004,14 @@ Q_OUTOFLINE_TEMPLATE int QList<T>::count(const T &t) const
return c;
}
+template <typename T>
+inline int QList<T>::count_impl(const T &t, QListData::ArrayCompatibleLayout) const
+{
+ return int(std::count(reinterpret_cast<const T*>(p.begin()),
+ reinterpret_cast<const T*>(p.end()),
+ t));
+}
+
Q_DECLARE_SEQUENTIAL_ITERATOR(List)
Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List)
diff --git a/src/corelib/tools/qlocale_mac.mm b/src/corelib/tools/qlocale_mac.mm
index 4532f4b391..b581e33aef 100644
--- a/src/corelib/tools/qlocale_mac.mm
+++ b/src/corelib/tools/qlocale_mac.mm
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
+** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h
index aa0a53388c..d637067fa8 100644
--- a/src/corelib/tools/qpair.h
+++ b/src/corelib/tools/qpair.h
@@ -45,22 +45,31 @@ struct QPair
typedef T1 first_type;
typedef T2 second_type;
- Q_DECL_CONSTEXPR QPair() : first(), second() {}
- Q_DECL_CONSTEXPR QPair(const T1 &t1, const T2 &t2) : first(t1), second(t2) {}
+ Q_DECL_CONSTEXPR QPair()
+ Q_DECL_NOEXCEPT_EXPR(noexcept(T1()) && noexcept(T2()))
+ : first(), second() {}
+ Q_DECL_CONSTEXPR QPair(const T1 &t1, const T2 &t2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(T1(t1)) && noexcept(T2(t2)))
+ : first(t1), second(t2) {}
// compiler-generated copy/move ctor/assignment operators are fine!
template <typename TT1, typename TT2>
- Q_DECL_CONSTEXPR QPair(const QPair<TT1, TT2> &p) : first(p.first), second(p.second) {}
+ Q_DECL_CONSTEXPR QPair(const QPair<TT1, TT2> &p)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(T1(p.first)) && noexcept(T2(p.second)))
+ : first(p.first), second(p.second) {}
template <typename TT1, typename TT2>
Q_DECL_RELAXED_CONSTEXPR QPair &operator=(const QPair<TT1, TT2> &p)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(std::declval<T1&>() = p.first) && noexcept(std::declval<T2&>() = p.second))
{ first = p.first; second = p.second; return *this; }
#ifdef Q_COMPILER_RVALUE_REFS
template <typename TT1, typename TT2>
Q_DECL_CONSTEXPR QPair(QPair<TT1, TT2> &&p)
// can't use std::move here as it's not constexpr in C++11:
+ Q_DECL_NOEXCEPT_EXPR(noexcept(T1(static_cast<TT1 &&>(p.first))) && noexcept(T2(static_cast<TT2 &&>(p.second))))
: first(static_cast<TT1 &&>(p.first)), second(static_cast<TT2 &&>(p.second)) {}
template <typename TT1, typename TT2>
Q_DECL_RELAXED_CONSTEXPR QPair &operator=(QPair<TT1, TT2> &&p)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(std::declval<T1&>() = std::move(p.first)) && noexcept(std::declval<T2&>() = std::move(p.second)))
{ first = std::move(p.first); second = std::move(p.second); return *this; }
#endif
diff --git a/src/corelib/tools/qstring_mac.mm b/src/corelib/tools/qstring_mac.mm
index add4ed1328..c958710b3b 100644
--- a/src/corelib/tools/qstring_mac.mm
+++ b/src/corelib/tools/qstring_mac.mm
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
+** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp
index b6160a3fd8..c2ee99a2d8 100644
--- a/src/corelib/tools/qtimezone.cpp
+++ b/src/corelib/tools/qtimezone.cpp
@@ -378,12 +378,10 @@ QTimeZone::QTimeZone(int offsetSeconds)
QTimeZone::QTimeZone(const QByteArray &ianaId, int offsetSeconds, const QString &name,
const QString &abbreviation, QLocale::Country country, const QString &comment)
+ : d()
{
- // ianaId must be a valid ID and must not clash with the standard system names
- if (QTimeZonePrivate::isValidId(ianaId) && !availableTimeZoneIds().contains(ianaId))
+ if (!isTimeZoneIdAvailable(ianaId))
d = new QUtcTimeZonePrivate(ianaId, offsetSeconds, name, abbreviation, country, comment);
- else
- d = 0;
}
/*!
@@ -821,7 +819,20 @@ bool QTimeZone::isTimeZoneIdAvailable(const QByteArray &ianaId)
{
// isValidId is not strictly required, but faster to weed out invalid
// IDs as availableTimeZoneIds() may be slow
- return (QTimeZonePrivate::isValidId(ianaId) && (availableTimeZoneIds().contains(ianaId)));
+ if (!QTimeZonePrivate::isValidId(ianaId))
+ return false;
+ const QList<QByteArray> tzIds = availableTimeZoneIds();
+ return std::binary_search(tzIds.begin(), tzIds.end(), ianaId);
+}
+
+static QList<QByteArray> set_union(const QList<QByteArray> &l1, const QList<QByteArray> &l2)
+{
+ QList<QByteArray> result;
+ result.reserve(l1.size() + l2.size());
+ std::set_union(l1.begin(), l1.end(),
+ l2.begin(), l2.end(),
+ std::back_inserter(result));
+ return result;
}
/*!
@@ -832,11 +843,8 @@ bool QTimeZone::isTimeZoneIdAvailable(const QByteArray &ianaId)
QList<QByteArray> QTimeZone::availableTimeZoneIds()
{
- QSet<QByteArray> set = QUtcTimeZonePrivate().availableTimeZoneIds()
- + global_tz->backend->availableTimeZoneIds();
- QList<QByteArray> list = set.toList();
- std::sort(list.begin(), list.end());
- return list;
+ return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(),
+ global_tz->backend->availableTimeZoneIds());
}
/*!
@@ -852,11 +860,8 @@ QList<QByteArray> QTimeZone::availableTimeZoneIds()
QList<QByteArray> QTimeZone::availableTimeZoneIds(QLocale::Country country)
{
- QSet<QByteArray> set = QUtcTimeZonePrivate().availableTimeZoneIds(country)
- + global_tz->backend->availableTimeZoneIds(country);
- QList<QByteArray> list = set.toList();
- std::sort(list.begin(), list.end());
- return list;
+ return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(country),
+ global_tz->backend->availableTimeZoneIds(country));
}
/*!
@@ -868,11 +873,8 @@ QList<QByteArray> QTimeZone::availableTimeZoneIds(QLocale::Country country)
QList<QByteArray> QTimeZone::availableTimeZoneIds(int offsetSeconds)
{
- QSet<QByteArray> set = QUtcTimeZonePrivate().availableTimeZoneIds(offsetSeconds)
- + global_tz->backend->availableTimeZoneIds(offsetSeconds);
- QList<QByteArray> list = set.toList();
- std::sort(list.begin(), list.end());
- return list;
+ return set_union(QUtcTimeZonePrivate().availableTimeZoneIds(offsetSeconds),
+ global_tz->backend->availableTimeZoneIds(offsetSeconds));
}
/*!
diff --git a/src/corelib/tools/qtimezoneprivate.cpp b/src/corelib/tools/qtimezoneprivate.cpp
index 337f0e6bfb..164db5ed0c 100644
--- a/src/corelib/tools/qtimezoneprivate.cpp
+++ b/src/corelib/tools/qtimezoneprivate.cpp
@@ -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
@@ -682,31 +688,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
diff --git a/src/corelib/tools/qtimezoneprivate_android.cpp b/src/corelib/tools/qtimezoneprivate_android.cpp
index f7f4aaab06..6178fe935a 100644
--- a/src/corelib/tools/qtimezoneprivate_android.cpp
+++ b/src/corelib/tools/qtimezoneprivate_android.cpp
@@ -262,9 +262,9 @@ QByteArray QAndroidTimeZonePrivate::systemTimeZoneId() const
return systemTZid;
}
-QSet<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const
+QList<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const
{
- QSet<QByteArray> availableTimeZoneIdList;
+ QList<QByteArray> availableTimeZoneIdList;
QJNIObjectPrivate androidAvailableIdList = QJNIObjectPrivate::callStaticObjectMethod("java.util.TimeZone", "getAvailableIDs", "()[Ljava/lang/String;");
QJNIEnvironmentPrivate jniEnv;
@@ -277,7 +277,7 @@ QSet<QByteArray> QAndroidTimeZonePrivate::availableTimeZoneIds() const
for (int i=0; i<androidTZcount; i++ ) {
androidTZobject = jniEnv->GetObjectArrayElement( static_cast<jobjectArray>( androidAvailableIdList.object() ), i );
androidTZ = androidTZobject;
- availableTimeZoneIdList.insert( androidTZ.toString().toUtf8() );
+ availableTimeZoneIdList.append( androidTZ.toString().toUtf8() );
jniEnv->DeleteLocalRef(androidTZobject);
}
diff --git a/src/corelib/tools/qtimezoneprivate_icu.cpp b/src/corelib/tools/qtimezoneprivate_icu.cpp
index 3ab42661c0..dd57464a72 100644
--- a/src/corelib/tools/qtimezoneprivate_icu.cpp
+++ b/src/corelib/tools/qtimezoneprivate_icu.cpp
@@ -37,6 +37,9 @@
#include <unicode/ucal.h>
#include <qdebug.h>
+#include <qlist.h>
+
+#include <algorithm>
QT_BEGIN_NAMESPACE
@@ -234,19 +237,21 @@ static QTimeZonePrivate::Data ucalTimeZoneTransition(UCalendar *m_ucal,
#endif // U_ICU_VERSION_SHORT
// Convert a uenum to a QList<QByteArray>
-static QSet<QByteArray> uenumToIdSet(UEnumeration *uenum)
+static QList<QByteArray> uenumToIdList(UEnumeration *uenum)
{
- QSet<QByteArray> set;
+ QList<QByteArray> list;
int32_t size = 0;
UErrorCode status = U_ZERO_ERROR;
// TODO Perhaps use uenum_unext instead?
QByteArray result = uenum_next(uenum, &size, &status);
while (U_SUCCESS(status) && !result.isEmpty()) {
- set << result;
+ list << result;
status = U_ZERO_ERROR;
result = uenum_next(uenum, &size, &status);
}
- return set;
+ std::sort(list.begin(), list.end());
+ list.erase(std::unique(list.begin(), list.end()), list.end());
+ return list;
}
// Qt wrapper around ucal_getDSTSavings()
@@ -453,41 +458,41 @@ QByteArray QIcuTimeZonePrivate::systemTimeZoneId() const
return ucalDefaultTimeZoneId();
}
-QSet<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds() const
+QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds() const
{
UErrorCode status = U_ZERO_ERROR;
UEnumeration *uenum = ucal_openTimeZones(&status);
- QSet<QByteArray> set;
+ QList<QByteArray> result;
if (U_SUCCESS(status))
- set = uenumToIdSet(uenum);
+ result = uenumToIdList(uenum);
uenum_close(uenum);
- return set;
+ return result;
}
-QSet<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const
+QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const
{
QByteArray regionCode = QLocalePrivate::countryToCode(country).toUtf8();
UErrorCode status = U_ZERO_ERROR;
UEnumeration *uenum = ucal_openCountryTimeZones(regionCode, &status);
- QSet<QByteArray> set;
+ QList<QByteArray> result;
if (U_SUCCESS(status))
- set = uenumToIdSet(uenum);
+ result = uenumToIdList(uenum);
uenum_close(uenum);
- return set;
+ return result;
}
-QSet<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const
+QList<QByteArray> QIcuTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const
{
// TODO Available directly in C++ api but not C api, from 4.8 onwards new filter method works
#if U_ICU_VERSION_MAJOR_NUM >= 49 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM == 8)
UErrorCode status = U_ZERO_ERROR;
UEnumeration *uenum = ucal_openTimeZoneIDEnumeration(UCAL_ZONE_TYPE_ANY, 0,
&offsetFromUtc, &status);
- QSet<QByteArray> set;
+ QList<QByteArray> result;
if (U_SUCCESS(status))
- set = uenumToIdSet(uenum);
+ result = uenumToIdList(uenum);
uenum_close(uenum);
- return set;
+ return result;
#else
return QTimeZonePrivate::availableTimeZoneIds(offsetFromUtc);
#endif
diff --git a/src/corelib/tools/qtimezoneprivate_mac.mm b/src/corelib/tools/qtimezoneprivate_mac.mm
index b0c3c9e64f..f316fe0a6d 100644
--- a/src/corelib/tools/qtimezoneprivate_mac.mm
+++ b/src/corelib/tools/qtimezoneprivate_mac.mm
@@ -41,6 +41,8 @@
#include <qdebug.h>
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
/*
@@ -247,18 +249,21 @@ QByteArray QMacTimeZonePrivate::systemTimeZoneId() const
return QCFString::toQString([[NSTimeZone systemTimeZone] name]).toUtf8();
}
-QSet<QByteArray> QMacTimeZonePrivate::availableTimeZoneIds() const
+QList<QByteArray> QMacTimeZonePrivate::availableTimeZoneIds() const
{
NSEnumerator *enumerator = [[NSTimeZone knownTimeZoneNames] objectEnumerator];
QByteArray tzid = QCFString::toQString([enumerator nextObject]).toUtf8();
- QSet<QByteArray> set;
+ QList<QByteArray> list;
while (!tzid.isEmpty()) {
- set << tzid;
+ list << tzid;
tzid = QCFString::toQString([enumerator nextObject]).toUtf8();
}
- return set;
+ std::sort(list.begin(), list.end());
+ list.erase(std::unique(list.begin(), list.end()), list.end());
+
+ return list;
}
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qtimezoneprivate_p.h b/src/corelib/tools/qtimezoneprivate_p.h
index 609ed50c56..803ba1f57a 100644
--- a/src/corelib/tools/qtimezoneprivate_p.h
+++ b/src/corelib/tools/qtimezoneprivate_p.h
@@ -126,9 +126,9 @@ public:
virtual QByteArray systemTimeZoneId() const;
- virtual QSet<QByteArray> availableTimeZoneIds() const;
- virtual QSet<QByteArray> availableTimeZoneIds(QLocale::Country country) const;
- virtual QSet<QByteArray> availableTimeZoneIds(int utcOffset) const;
+ virtual QList<QByteArray> availableTimeZoneIds() const;
+ virtual QList<QByteArray> availableTimeZoneIds(QLocale::Country country) const;
+ virtual QList<QByteArray> availableTimeZoneIds(int utcOffset) const;
virtual void serialize(QDataStream &ds) const;
@@ -199,9 +199,9 @@ public:
QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds(int utcOffset) const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds(int utcOffset) const Q_DECL_OVERRIDE;
void serialize(QDataStream &ds) const Q_DECL_OVERRIDE;
@@ -250,9 +250,9 @@ public:
QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds(int offsetFromUtc) const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds(int offsetFromUtc) const Q_DECL_OVERRIDE;
private:
void init(const QByteArray &ianaId);
@@ -318,8 +318,8 @@ public:
QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE;
private:
void init(const QByteArray &ianaId);
@@ -369,7 +369,7 @@ public:
QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
private:
void init(const QByteArray &zoneId);
@@ -420,7 +420,7 @@ public:
QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
private:
void init(const QByteArray &ianaId);
@@ -470,7 +470,7 @@ public:
QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE;
- QSet<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
+ QList<QByteArray> availableTimeZoneIds() const Q_DECL_OVERRIDE;
private:
void init(const QByteArray &zoneId);
diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp
index 0d8ae3b47f..29f0e17012 100644
--- a/src/corelib/tools/qtimezoneprivate_tz.cpp
+++ b/src/corelib/tools/qtimezoneprivate_tz.cpp
@@ -41,6 +41,7 @@
#include <qdebug.h>
+#include <algorithm>
QT_BEGIN_NAMESPACE
@@ -956,20 +957,23 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const
return ianaId;
}
-QSet<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds() const
+QList<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds() const
{
- return tzZones->keys().toSet();
+ QList<QByteArray> result = tzZones->keys();
+ std::sort(result.begin(), result.end());
+ return result;
}
-QSet<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const
+QList<QByteArray> QTzTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const
{
// TODO AnyCountry
- QSet<QByteArray> set;
+ QList<QByteArray> result;
foreach (const QByteArray &key, tzZones->keys()) {
if (tzZones->value(key).country == country)
- set << key;
+ result << key;
}
- return set;
+ std::sort(result.begin(), result.end());
+ return result;
}
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qtimezoneprivate_win.cpp b/src/corelib/tools/qtimezoneprivate_win.cpp
index 2d0caf07a8..a9bb3aa3b5 100644
--- a/src/corelib/tools/qtimezoneprivate_win.cpp
+++ b/src/corelib/tools/qtimezoneprivate_win.cpp
@@ -38,6 +38,8 @@
#include "qdebug.h"
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
/*
@@ -632,14 +634,16 @@ QByteArray QWinTimeZonePrivate::systemTimeZoneId() const
return ianaId;
}
-QSet<QByteArray> QWinTimeZonePrivate::availableTimeZoneIds() const
+QList<QByteArray> QWinTimeZonePrivate::availableTimeZoneIds() const
{
- QSet<QByteArray> set;
+ QList<QByteArray> result;
foreach (const QByteArray &winId, availableWindowsIds()) {
foreach (const QByteArray &ianaId, windowsIdToIanaIds(winId))
- set << ianaId;
+ result << ianaId;
}
- return set;
+ std::sort(result.begin(), result.end());
+ result.erase(std::unique(result.begin(), result.end()), result.end());
+ return result;
}
QWinTimeZonePrivate::QWinTransitionRule QWinTimeZonePrivate::ruleForYear(int year) const
diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp
index 10e3f57140..660f40b107 100644
--- a/src/corelib/tools/qversionnumber.cpp
+++ b/src/corelib/tools/qversionnumber.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
+** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2014 Keith Gardner <kreios4004@gmail.com>
** Contact: http://www.qt.io/licensing/
**
diff --git a/src/corelib/tools/qversionnumber_p.h b/src/corelib/tools/qversionnumber_p.h
index 4d42995ef7..2da3103be3 100644
--- a/src/corelib/tools/qversionnumber_p.h
+++ b/src/corelib/tools/qversionnumber_p.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
+** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2014 Keith Gardner <kreios4004@gmail.com>
** Contact: http://www.qt.io/licensing/
**