From 81a45e1f13fdf56129aed952a6e3479e16c14a2c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 26 Jul 2014 01:43:18 +0200 Subject: QTimeZone: don't use QSet, use sorted QList QSet, as a node-based container, requires one memory allocation per element inserted. QList, as a contiguous-memory container (at least in the case of a QByteArray payload), requires one memory allocation per container. The higher lookup speed might still speak for using QSet, but there are only two uses of the sets: 1. Checking for existence (or lack thereof) of timezone names. For this, first generating a container full of data just to check for existence of one item of data is extremely wasteful. The QTZPrivate API should be extended to allow said lookup to be performed on the native data store instead. That leaves 2. Returning a sorted(!) list(!) from the public QTimeZone API. There is no reason why, during the construction of those sorted lists, the data should be held in a set. Instead, the well-known technique of first cramming everything into a result container, which is subsequently sorted and has its duplicates removed, can be used here. Saves more than 8K of text size on AMD64 stripped release builds. Change-Id: I71c2298e94e02d55b0c9fb6f7ebeaed79a1fe2db Reviewed-by: Thiago Macieira --- src/corelib/tools/qtimezone.cpp | 42 +++++++++-------- src/corelib/tools/qtimezoneprivate.cpp | 74 +++++++++++++++++------------- src/corelib/tools/qtimezoneprivate_icu.cpp | 37 ++++++++------- src/corelib/tools/qtimezoneprivate_mac.mm | 13 ++++-- src/corelib/tools/qtimezoneprivate_p.h | 26 +++++------ src/corelib/tools/qtimezoneprivate_tz.cpp | 16 ++++--- src/corelib/tools/qtimezoneprivate_win.cpp | 12 +++-- 7 files changed, 125 insertions(+), 95 deletions(-) (limited to 'src/corelib') 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 tzIds = availableTimeZoneIds(); + return std::binary_search(tzIds.begin(), tzIds.end(), ianaId); +} + +static QList set_union(const QList &l1, const QList &l2) +{ + QList 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 QTimeZone::availableTimeZoneIds() { - QSet set = QUtcTimeZonePrivate().availableTimeZoneIds() - + global_tz->backend->availableTimeZoneIds(); - QList 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 QTimeZone::availableTimeZoneIds() QList QTimeZone::availableTimeZoneIds(QLocale::Country country) { - QSet set = QUtcTimeZonePrivate().availableTimeZoneIds(country) - + global_tz->backend->availableTimeZoneIds(country); - QList 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 QTimeZone::availableTimeZoneIds(QLocale::Country country) QList QTimeZone::availableTimeZoneIds(int offsetSeconds) { - QSet set = QUtcTimeZonePrivate().availableTimeZoneIds(offsetSeconds) - + global_tz->backend->availableTimeZoneIds(offsetSeconds); - QList 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 #include +#include + QT_BEGIN_NAMESPACE enum { @@ -341,36 +343,38 @@ QByteArray QTimeZonePrivate::systemTimeZoneId() const return QByteArray(); } -QSet QTimeZonePrivate::availableTimeZoneIds() const +QList QTimeZonePrivate::availableTimeZoneIds() const { - return QSet(); + return QList(); } -QSet QTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const +QList QTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const { // Default fall-back mode, use the zoneTable to find Region of know Zones - QSet regionSet; + QList 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 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 all = availableTimeZoneIds(); + QList 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 QTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const +QList QTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const { // Default fall-back mode, use the zoneTable to find Offset of know Zones - QSet offsetSet; + QList 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 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 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 all = availableTimeZoneIds(); + QList 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 QUtcTimeZonePrivate::availableTimeZoneIds() const +QList QUtcTimeZonePrivate::availableTimeZoneIds() const { - QSet set; + QList 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 QUtcTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const +QList 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(); + return QList(); } -QSet QUtcTimeZonePrivate::availableTimeZoneIds(qint32 offsetSeconds) const +QList QUtcTimeZonePrivate::availableTimeZoneIds(qint32 offsetSeconds) const { - QSet set; + QList 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_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 #include +#include + +#include 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 -static QSet uenumToIdSet(UEnumeration *uenum) +static QList uenumToIdList(UEnumeration *uenum) { - QSet set; + QList 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 QIcuTimeZonePrivate::availableTimeZoneIds() const +QList QIcuTimeZonePrivate::availableTimeZoneIds() const { UErrorCode status = U_ZERO_ERROR; UEnumeration *uenum = ucal_openTimeZones(&status); - QSet set; + QList result; if (U_SUCCESS(status)) - set = uenumToIdSet(uenum); + result = uenumToIdList(uenum); uenum_close(uenum); - return set; + return result; } -QSet QIcuTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const +QList QIcuTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const { QByteArray regionCode = QLocalePrivate::countryToCode(country).toUtf8(); UErrorCode status = U_ZERO_ERROR; UEnumeration *uenum = ucal_openCountryTimeZones(regionCode, &status); - QSet set; + QList result; if (U_SUCCESS(status)) - set = uenumToIdSet(uenum); + result = uenumToIdList(uenum); uenum_close(uenum); - return set; + return result; } -QSet QIcuTimeZonePrivate::availableTimeZoneIds(int offsetFromUtc) const +QList 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 set; + QList 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 +#include + QT_BEGIN_NAMESPACE /* @@ -247,18 +249,21 @@ QByteArray QMacTimeZonePrivate::systemTimeZoneId() const return QCFString::toQString([[NSTimeZone systemTimeZone] name]).toUtf8(); } -QSet QMacTimeZonePrivate::availableTimeZoneIds() const +QList QMacTimeZonePrivate::availableTimeZoneIds() const { NSEnumerator *enumerator = [[NSTimeZone knownTimeZoneNames] objectEnumerator]; QByteArray tzid = QCFString::toQString([enumerator nextObject]).toUtf8(); - QSet set; + QList 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..64827950e2 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 availableTimeZoneIds() const; - virtual QSet availableTimeZoneIds(QLocale::Country country) const; - virtual QSet availableTimeZoneIds(int utcOffset) const; + virtual QList availableTimeZoneIds() const; + virtual QList availableTimeZoneIds(QLocale::Country country) const; + virtual QList availableTimeZoneIds(int utcOffset) const; virtual void serialize(QDataStream &ds) const; @@ -199,9 +199,9 @@ public: QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE; - QSet availableTimeZoneIds() const Q_DECL_OVERRIDE; - QSet availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE; - QSet availableTimeZoneIds(int utcOffset) const Q_DECL_OVERRIDE; + QList availableTimeZoneIds() const Q_DECL_OVERRIDE; + QList availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE; + QList 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 availableTimeZoneIds() const Q_DECL_OVERRIDE; - QSet availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE; - QSet availableTimeZoneIds(int offsetFromUtc) const Q_DECL_OVERRIDE; + QList availableTimeZoneIds() const Q_DECL_OVERRIDE; + QList availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE; + QList 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 availableTimeZoneIds() const Q_DECL_OVERRIDE; - QSet availableTimeZoneIds(QLocale::Country country) const Q_DECL_OVERRIDE; + QList availableTimeZoneIds() const Q_DECL_OVERRIDE; + QList 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 availableTimeZoneIds() const Q_DECL_OVERRIDE; + QList availableTimeZoneIds() const Q_DECL_OVERRIDE; private: void init(const QByteArray &zoneId); @@ -420,7 +420,7 @@ public: QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE; - QSet availableTimeZoneIds() const Q_DECL_OVERRIDE; + QList availableTimeZoneIds() const Q_DECL_OVERRIDE; private: void init(const QByteArray &ianaId); 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 +#include QT_BEGIN_NAMESPACE @@ -956,20 +957,23 @@ QByteArray QTzTimeZonePrivate::systemTimeZoneId() const return ianaId; } -QSet QTzTimeZonePrivate::availableTimeZoneIds() const +QList QTzTimeZonePrivate::availableTimeZoneIds() const { - return tzZones->keys().toSet(); + QList result = tzZones->keys(); + std::sort(result.begin(), result.end()); + return result; } -QSet QTzTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const +QList QTzTimeZonePrivate::availableTimeZoneIds(QLocale::Country country) const { // TODO AnyCountry - QSet set; + QList 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 + QT_BEGIN_NAMESPACE /* @@ -632,14 +634,16 @@ QByteArray QWinTimeZonePrivate::systemTimeZoneId() const return ianaId; } -QSet QWinTimeZonePrivate::availableTimeZoneIds() const +QList QWinTimeZonePrivate::availableTimeZoneIds() const { - QSet set; + QList 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 -- cgit v1.2.3 From 62475eb8b09ab1d26ba02032e110bb44872392a6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 20 Jan 2015 23:48:22 +0100 Subject: QDateTime: change an instance of out parameters to return-by-value Compilers don't like out parameters. Effects on Linux GCC 4.9 stripped release builds: text -528B data +-0B relocs +-0 Change-Id: I32ee1a6c4388900bacfc6eb20feb4b81d71cb1f2 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 100 +++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 52 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index adfcbcecf0..a25e913d92 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; } /***************************************************************************** @@ -449,9 +450,7 @@ int QDate::year() const if (isNull()) return 0; - int y; - getDateFromJulianDay(jd, &y, 0, 0); - return y; + return getDateFromJulianDay(jd).year; } /*! @@ -483,9 +482,7 @@ int QDate::month() const if (isNull()) return 0; - int m; - getDateFromJulianDay(jd, 0, &m, 0); - return m; + return getDateFromJulianDay(jd).month; } /*! @@ -501,9 +498,7 @@ int QDate::day() const if (isNull()) return 0; - int d; - getDateFromJulianDay(jd, 0, 0, &d); - return d; + return getDateFromJulianDay(jd).day; } /*! @@ -555,12 +550,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 +570,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 +887,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 +905,19 @@ 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::fromLatin1("%1-%2-%3").arg(pd.year, 4, 10, QLatin1Char('0')) + .arg(pd.month, 2, 10, QLatin1Char('0')) + .arg(pd.day, 2, 10, QLatin1Char('0')); } } @@ -1031,16 +1023,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 +1074,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 +1137,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); } /*! -- cgit v1.2.3 From d8d114989ab653cf77304cafc65392d295212c00 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Jan 2015 00:51:34 +0100 Subject: QDateTime: optimize rfcDateImpl() Get the captured texts once and use indexing into the QStringList instead of repeatedly calling QRegExp::cap(n). (Impressive) effects on Linux GCC 4.9 stripped release builds: text -2876B data +-0B relocs +-0 Change-Id: I3a02eab1a691f31c30654cd89a0c030414b40de0 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index a25e913d92..a31e91db97 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -202,20 +202,21 @@ static void rfcDateImpl(const QString &s, QDate *dd = 0, QTime *dt = 0, int *utc // 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) { + const QStringList cap = rex.capturedTexts(); if (dd) { - day = rex.cap(1).toInt(); - month = qt_monthNumberFromShortName(rex.cap(2)); - year = rex.cap(3).toInt(); + day = cap[1].toInt(); + month = qt_monthNumberFromShortName(cap[2]); + year = 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(); + if (!cap[4].isEmpty()) { + hour = cap[4].toInt(); + min = cap[5].toInt(); + sec = cap[6].toInt(); } - positiveOffset = (rex.cap(7) == QLatin1String("+")); - hourOffset = rex.cap(8).toInt(); - minOffset = rex.cap(9).toInt(); + positiveOffset = (cap[7] == QLatin1String("+")); + hourOffset = cap[8].toInt(); + minOffset = cap[9].toInt(); } if (utcOffset) *utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60)); @@ -223,20 +224,21 @@ static void rfcDateImpl(const QString &s, QDate *dd = 0, QTime *dt = 0, int *utc // 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) { + const QStringList cap = rex.capturedTexts(); if (dd) { - month = qt_monthNumberFromShortName(rex.cap(1)); - day = rex.cap(2).toInt(); - year = rex.cap(6).toInt(); + month = qt_monthNumberFromShortName(cap[1]); + day = cap[2].toInt(); + year = 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(); + if (!cap[3].isEmpty()) { + hour = cap[3].toInt(); + min = cap[4].toInt(); + sec = cap[5].toInt(); } - positiveOffset = (rex.cap(7) == QLatin1String("+")); - hourOffset = rex.cap(8).toInt(); - minOffset = rex.cap(9).toInt(); + positiveOffset = (cap[7] == QLatin1String("+")); + hourOffset = cap[8].toInt(); + minOffset = cap[9].toInt(); } if (utcOffset) *utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60)); -- cgit v1.2.3 From 70bfc75d18cfabf07e7a2cac016f729fb46bd2d7 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Jan 2015 10:17:00 +0100 Subject: QDateTime: replace out parameters with return-by-value in rfcDateImpl() Compilers *really* don't like out parameters. (Impressive) effects on Linux GCC 4.9 stripped release builds: text -2512B data +-0B relocs +-0 Change-Id: I0fe370a438f7b82aaa9cc04ddd56e45a5969e7a9 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 98 ++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 66 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index a31e91db97..e366717d96 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -187,68 +187,43 @@ 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) { const QStringList cap = rex.capturedTexts(); - if (dd) { - day = cap[1].toInt(); - month = qt_monthNumberFromShortName(cap[2]); - year = cap[3].toInt(); - } - if (dt) { - if (!cap[4].isEmpty()) { - hour = cap[4].toInt(); - min = cap[5].toInt(); - sec = cap[6].toInt(); - } - positiveOffset = (cap[7] == QLatin1String("+")); - hourOffset = cap[8].toInt(); - minOffset = cap[9].toInt(); - } - if (utcOffset) - *utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60)); + 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) { const QStringList cap = rex.capturedTexts(); - if (dd) { - month = qt_monthNumberFromShortName(cap[1]); - day = cap[2].toInt(); - year = cap[6].toInt(); - } - if (dt) { - if (!cap[3].isEmpty()) { - hour = cap[3].toInt(); - min = cap[4].toInt(); - sec = cap[5].toInt(); - } - positiveOffset = (cap[7] == QLatin1String("+")); - hourOffset = cap[8].toInt(); - minOffset = cap[9].toInt(); - } - if (utcOffset) - *utcOffset = ((hourOffset * 60 + minOffset) * (positiveOffset ? 60 : -60)); + 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 @@ -1253,11 +1228,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: { @@ -2001,11 +1973,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: @@ -4415,16 +4384,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: { -- cgit v1.2.3 From df0d933db519620f02034ed0f1477b77dabdb8f4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Jan 2015 23:18:40 +0100 Subject: QDateTimePrivate: remove pointless copy ctor The compiler-generated one is just as fine, more maintainable, and doesn't inhibit moves (which probably doesn't matter here). No change in executable code size. Change-Id: Ideee493a5911808430d3e09e6eb07e91d7a19b12 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime_p.h | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index d703442963..99d69a575d 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 -- cgit v1.2.3 From 94078f864577d9bd08cb17eb4b695e5d03ac1b3e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Jan 2015 23:29:52 +0100 Subject: QDateTimePrivate: remove pointless comparisons For any 1-bit flag: bool(var & flag) <=> (var & flag) == flag but gcc didn't seem to get it: (Surprising) effects on Linux GCC 4.9 stripped release builds: text -4936B (!!) data +-0B relocs +-0 It seems this enables some dead code detection, but I must confess I don't quite understand how such a small change can have such a dramatic effect on the executable size, even after diffing the assembler output. Change-Id: Ia307fde0de16160ea51bbb3ed6c1ff203d4f9091 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime_p.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index 99d69a575d..78e9d6cabd 100644 --- a/src/corelib/tools/qdatetime_p.h +++ b/src/corelib/tools/qdatetime_p.h @@ -126,14 +126,14 @@ 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 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 = m_status | ValidDateTime; } inline void clearValidDateTime() { m_status = m_status & ~ValidDateTime; } - inline bool isTimeZoneCached() const { return (m_status & TimeZoneCached) == TimeZoneCached; } + inline bool isTimeZoneCached() const { return m_status & 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; } -- cgit v1.2.3 From 5b7729ae79cea9c75d297ecfa043ab329f84bc3b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 21 Jan 2015 23:50:05 +0100 Subject: QDateTimePrivate: make bit manipulation code more readable ...by using var op= ... instead of var = var op ... No change in executable code size. Change-Id: I1c29ff6700f0f21be07768af8d002f0823c89fbd Reviewed-by: Oswald Buddenhagen --- src/corelib/tools/qdatetime_p.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index 78e9d6cabd..a139390a9d 100644 --- a/src/corelib/tools/qdatetime_p.h +++ b/src/corelib/tools/qdatetime_p.h @@ -131,12 +131,12 @@ public: 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 = m_status | ValidDateTime; } - inline void clearValidDateTime() { m_status = 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 = m_status | TimeZoneCached; } - inline void clearTimeZoneCached() { m_status = m_status & ~TimeZoneCached; } - inline void clearSetToDaylightStatus() { m_status = m_status & ~SetToStandardTime & ~SetToDaylightTime; } + 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, -- cgit v1.2.3 From 8f553484fa1d0ef7db026723ef8b1cbe79f85faa Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 22 Jan 2015 12:23:14 +0100 Subject: QDateTime: optimize toOffsetString() Instead of using a QString::arg() cascade, which creates tons of temporaries, use good 'ol sprintf(). As a consequence, this function is now inlined into all four callers and the total executable size _still_ goes down: Effects on Linux GCC 4.9 stripped release builds: text -420B data +-0B relocs +-0 Change-Id: I10d6abd94b489db7c2f01dc5424f30a798602522 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index e366717d96..b31eb8c23c 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -228,18 +228,14 @@ static ParsedRfcDateTime rfcDateImpl(const QString &s) #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 -- cgit v1.2.3 From 647ad3fe2510d49299ee496a4d8db2058d832db1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 22 Jan 2015 12:34:44 +0100 Subject: QDate: optimize QDate::toString() Instead of using a QString::arg() cascade, which creates tons of temporaries, use good 'ol sprintf(). Effects on Linux GCC 4.9 stripped release builds: text -216B data +-0B relocs +-0 Change-Id: I6ff551cb9f42e0c05a64f03a8e177fb527915481 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index b31eb8c23c..191fcf8cfd 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -888,9 +888,7 @@ QString QDate::toString(Qt::DateFormat format) const pd = getDateFromJulianDay(jd); if (pd.year < 0 || pd.year > 9999) return QString(); - return QString::fromLatin1("%1-%2-%3").arg(pd.year, 4, 10, QLatin1Char('0')) - .arg(pd.month, 2, 10, QLatin1Char('0')) - .arg(pd.day, 2, 10, QLatin1Char('0')); + return QString::asprintf("%04d-%02d-%02d", pd.year, pd.month, pd.day); } } -- cgit v1.2.3 From 40d6e8adf5e3cc45b3bd4a94ad3b57f9444e447f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 1 Oct 2014 10:56:14 +0200 Subject: QList: prepare for tag dispatching based on memory layout Add one tag class for each of QList's three different memory layouts to QListData, and inherit QList::MemoryLayout from exactly one of them. To simplify overloading, added tag classes that express the negation of the two extreme poles of memory layout (C-compatible and heap), too. The "missing" one could be added when needed, too. Change-Id: I45ea603731499fd3fdfb37d60a0a98fb22ac15ec Reviewed-by: Thiago Macieira --- src/corelib/tools/qlist.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 023dafb223..255816d0ba 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -66,6 +66,14 @@ template struct QListSpecialMethods { }; template <> struct QListSpecialMethods; 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 class QList : public QListSpecialMethods { +public: + struct MemoryLayout + : QtPrivate::if_< + QTypeInfo::isStatic || QTypeInfo::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(); -- cgit v1.2.3 From 18885297de880493831f63d20a8d45c6689a01b8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 19 Aug 2014 23:30:38 +0200 Subject: QList: share the implementations of contains()/count() with QVector where possible If QList data-layout-compatible with QVector and a C array, implement count() via std::count() and contains() via std::find() and use const_pointer instead of const_iterator as the iterators. This essentially makes the QVector and QList implementations identical to each other, at least for important cases such as QString. To switch between the different implementations, use tag dispatching instead of the previously used technique "use 'if' as if it were 'static if'", which imposes accidental requirements on the element types (something that esp. QVector is plagued with). Change-Id: I6caf74442a22059676b5bf115a6089768f3a0952 Reviewed-by: Thiago Macieira --- src/corelib/tools/qlist.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 255816d0ba..5d6cf9fe15 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -377,6 +377,12 @@ private: { return (constBegin().i <= i.i) && (i.i <= constEnd().i); } + +private: + 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) @@ -940,6 +946,12 @@ Q_OUTOFLINE_TEMPLATE int QList::lastIndexOf(const T &t, int from) const template Q_OUTOFLINE_TEMPLATE bool QList::contains(const T &t) const +{ + return contains_impl(t, MemoryLayout()); +} + +template +inline bool QList::contains_impl(const T &t, QListData::NotArrayCompatibleLayout) const { Node *e = reinterpret_cast(p.end()); Node *i = reinterpret_cast(p.begin()); @@ -949,8 +961,22 @@ Q_OUTOFLINE_TEMPLATE bool QList::contains(const T &t) const return false; } +template +inline bool QList::contains_impl(const T &t, QListData::ArrayCompatibleLayout) const +{ + const T *b = reinterpret_cast(p.begin()); + const T *e = reinterpret_cast(p.end()); + return std::find(b, e, t) != e; +} + template Q_OUTOFLINE_TEMPLATE int QList::count(const T &t) const +{ + return this->count_impl(t, MemoryLayout()); +} + +template +inline int QList::count_impl(const T &t, QListData::NotArrayCompatibleLayout) const { int c = 0; Node *e = reinterpret_cast(p.end()); @@ -961,6 +987,14 @@ Q_OUTOFLINE_TEMPLATE int QList::count(const T &t) const return c; } +template +inline int QList::count_impl(const T &t, QListData::ArrayCompatibleLayout) const +{ + return int(std::count(reinterpret_cast(p.begin()), + reinterpret_cast(p.end()), + t)); +} + Q_DECLARE_SEQUENTIAL_ITERATOR(List) Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(List) -- cgit v1.2.3 From ddd61b4aec7d17741faffe988b44c7c0a19ce71f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 26 Aug 2014 10:53:42 +0200 Subject: QList: share implementation of operator== with QVector where possible Same change as was already applied for count() and contains(). Change-Id: Ibd62e4b36e03741993ba33e730c9449ef19bff5f Reviewed-by: Thiago Macieira --- src/corelib/tools/qlist.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 5d6cf9fe15..57e67d52d7 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -379,6 +379,8 @@ private: } 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; @@ -796,6 +798,12 @@ Q_OUTOFLINE_TEMPLATE bool QList::operator==(const QList &l) const return true; if (p.size() != l.p.size()) return false; + return this->op_eq_impl(l, MemoryLayout()); +} + +template +inline bool QList::op_eq_impl(const QList &l, QListData::NotArrayCompatibleLayout) const +{ Node *i = reinterpret_cast(p.begin()); Node *e = reinterpret_cast(p.end()); Node *li = reinterpret_cast(l.p.begin()); @@ -806,6 +814,15 @@ Q_OUTOFLINE_TEMPLATE bool QList::operator==(const QList &l) const return true; } +template +inline bool QList::op_eq_impl(const QList &l, QListData::ArrayCompatibleLayout) const +{ + const T *lb = reinterpret_cast(l.p.begin()); + const T *b = reinterpret_cast(p.begin()); + const T *e = reinterpret_cast(p.end()); + return std::equal(b, e, lb); +} + template Q_OUTOFLINE_TEMPLATE void QList::dealloc(QListData::Data *data) { -- cgit v1.2.3 From 1649b973fd2ecd6c2398387f8bb5d0d768142336 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 19 Jan 2015 20:58:41 +0100 Subject: QPair: add noexcept to ctors and assignment operators Change-Id: Id201d1f1e7a087083ca6c13ab31c721e672ef566 Reviewed-by: Thiago Macieira --- src/corelib/tools/qpair.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/corelib') 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 - Q_DECL_CONSTEXPR QPair(const QPair &p) : first(p.first), second(p.second) {} + Q_DECL_CONSTEXPR QPair(const QPair &p) + Q_DECL_NOEXCEPT_EXPR(noexcept(T1(p.first)) && noexcept(T2(p.second))) + : first(p.first), second(p.second) {} template Q_DECL_RELAXED_CONSTEXPR QPair &operator=(const QPair &p) + Q_DECL_NOEXCEPT_EXPR(noexcept(std::declval() = p.first) && noexcept(std::declval() = p.second)) { first = p.first; second = p.second; return *this; } #ifdef Q_COMPILER_RVALUE_REFS template Q_DECL_CONSTEXPR QPair(QPair &&p) // can't use std::move here as it's not constexpr in C++11: + Q_DECL_NOEXCEPT_EXPR(noexcept(T1(static_cast(p.first))) && noexcept(T2(static_cast(p.second)))) : first(static_cast(p.first)), second(static_cast(p.second)) {} template Q_DECL_RELAXED_CONSTEXPR QPair &operator=(QPair &&p) + Q_DECL_NOEXCEPT_EXPR(noexcept(std::declval() = std::move(p.first)) && noexcept(std::declval() = std::move(p.second))) { first = std::move(p.first); second = std::move(p.second); return *this; } #endif -- cgit v1.2.3 From cb95fff1c7dfcfc00b1bf93d18b80485aca9dd0c Mon Sep 17 00:00:00 2001 From: Jani Heikkinen Date: Mon, 16 Feb 2015 11:44:46 +0200 Subject: Fixed license headers Change-Id: Ibebe1318d1c2de97601aa07269705c87737083ee Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qfilesystemwatcher_fsevents.mm | 2 +- src/corelib/io/qsettings_winrt.cpp | 2 +- src/corelib/io/qstandardpaths_ios.mm | 2 +- src/corelib/io/qurl_mac.mm | 2 +- src/corelib/kernel/qcore_mac_objc.mm | 2 +- src/corelib/tools/qbytearray_mac.mm | 2 +- src/corelib/tools/qbytearraylist.cpp | 2 +- src/corelib/tools/qbytearraylist.h | 2 +- src/corelib/tools/qdatetime_mac.mm | 2 +- src/corelib/tools/qlocale_mac.mm | 2 +- src/corelib/tools/qstring_mac.mm | 2 +- src/corelib/tools/qversionnumber.cpp | 2 +- src/corelib/tools/qversionnumber_p.h | 2 +- src/corelib/xml/make-parser.sh | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.mm b/src/corelib/io/qfilesystemwatcher_fsevents.mm index 1076b8f5b4..8a028c91e1 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.mm +++ b/src/corelib/io/qfilesystemwatcher_fsevents.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/io/qsettings_winrt.cpp b/src/corelib/io/qsettings_winrt.cpp index bf8b157d00..02c3c7624e 100644 --- a/src/corelib/io/qsettings_winrt.cpp +++ b/src/corelib/io/qsettings_winrt.cpp @@ -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/io/qstandardpaths_ios.mm b/src/corelib/io/qstandardpaths_ios.mm index 98e939cbda..27d28526c2 100644 --- a/src/corelib/io/qstandardpaths_ios.mm +++ b/src/corelib/io/qstandardpaths_ios.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/io/qurl_mac.mm b/src/corelib/io/qurl_mac.mm index f051dfbd32..a1fa7e4fc4 100644 --- a/src/corelib/io/qurl_mac.mm +++ b/src/corelib/io/qurl_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/kernel/qcore_mac_objc.mm b/src/corelib/kernel/qcore_mac_objc.mm index 53a15ce0bc..a215557aed 100644 --- a/src/corelib/kernel/qcore_mac_objc.mm +++ b/src/corelib/kernel/qcore_mac_objc.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/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 -** 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_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/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/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/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 ** 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 ** Contact: http://www.qt.io/licensing/ ** diff --git a/src/corelib/xml/make-parser.sh b/src/corelib/xml/make-parser.sh index 79a52f6e9e..2514661994 100755 --- a/src/corelib/xml/make-parser.sh +++ b/src/corelib/xml/make-parser.sh @@ -1,7 +1,7 @@ #!/bin/sh ############################################################################# ## -## 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 the build configuration utility of the Qt Toolkit. -- cgit v1.2.3 From 3769f7c974e7df8d240e90cbaafae60626053d26 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 3 Oct 2014 21:11:26 +0200 Subject: QDate/QTime: mark some functions constexpr Change-Id: Icbac388337d561f61a9a53163c3ddfc748935a2f Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.h | 54 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src/corelib') 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::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::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; -- cgit v1.2.3 From 72d5c84407ad0eb1c4e660343ec456280e874595 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Thu, 22 Jan 2015 13:31:19 +0300 Subject: Doc: Fix QTextStream::readLine() snippet The old snippet is incomplete because it misses an extra check in the loop body that the line is not null. Use the new readLine() overload to keep it simple. Change-Id: Ie9f13291ca6ff6f546b81f100ce58d747f0dd12f Reviewed-by: Oswald Buddenhagen --- src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp index 3d04f5b526..c76a0f1f3b 100644 --- a/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp @@ -51,9 +51,9 @@ if (data.open(QFile::WriteOnly | QFile::Truncate)) { //! [1] QTextStream stream(stdin); QString line; -do { - line = stream.readLine(); -} while (!line.isNull()); +while (stream.readLine(&line)) { + ... +} //! [1] -- cgit v1.2.3 From c38b6a3fde3da8f768d83818cc12ee34b717370b Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Wed, 18 Feb 2015 11:37:09 +0000 Subject: Disable constexpr support for QNX Even though the compiler on QNX supports C++11, the stdlib it ships with is missing constexpr on many important functions. This is required to make qtbase compile on QNX 6.6. Change-Id: I59a4263483b1d94b9d2dceb947876e445f9662af Reviewed-by: Rafael Roquetto --- src/corelib/global/qcompilerdetection.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 8ef8b79902..fa8a529d0c 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -903,6 +903,11 @@ # undef Q_COMPILER_UNICODE_STRINGS # undef Q_COMPILER_NOEXCEPT # endif +# if defined(_HAS_DINKUM_CLIB) && !defined(_HAS_CONSTEXPR) +// The libcpp is missing constexpr keywords on important functions like std::numeric_limits<>::min() +// Disable constexpr support on QNX even if the compiler supports it +# undef Q_COMPILER_CONSTEXPR +# endif # endif // Q_OS_QNX # if (defined(Q_CC_CLANG) || defined(Q_CC_INTEL)) && defined(Q_OS_MAC) && defined(__GNUC_LIBSTD__) \ && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402) -- cgit v1.2.3 From edb2ad9117ee1598f18ad79fd2493ca53b0c9513 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Thu, 19 Feb 2015 15:44:03 +0100 Subject: Fix compilation on Android Commit 81a45e1f13fdf56129aed952a6e3479e16c14a2c replaced QSets with QLists in QTimeZone, but forgot to adapt the Android code. This commit fixes it. Change-Id: I8704a39c44a9dc74147a4bb99a6f5d1bea53afa1 Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira Reviewed-by: Alex Blasche --- src/corelib/tools/qtimezoneprivate_android.cpp | 6 +++--- src/corelib/tools/qtimezoneprivate_p.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib') 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 QAndroidTimeZonePrivate::availableTimeZoneIds() const +QList QAndroidTimeZonePrivate::availableTimeZoneIds() const { - QSet availableTimeZoneIdList; + QList availableTimeZoneIdList; QJNIObjectPrivate androidAvailableIdList = QJNIObjectPrivate::callStaticObjectMethod("java.util.TimeZone", "getAvailableIDs", "()[Ljava/lang/String;"); QJNIEnvironmentPrivate jniEnv; @@ -277,7 +277,7 @@ QSet QAndroidTimeZonePrivate::availableTimeZoneIds() const for (int i=0; iGetObjectArrayElement( static_cast( 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_p.h b/src/corelib/tools/qtimezoneprivate_p.h index 64827950e2..803ba1f57a 100644 --- a/src/corelib/tools/qtimezoneprivate_p.h +++ b/src/corelib/tools/qtimezoneprivate_p.h @@ -470,7 +470,7 @@ public: QByteArray systemTimeZoneId() const Q_DECL_OVERRIDE; - QSet availableTimeZoneIds() const Q_DECL_OVERRIDE; + QList availableTimeZoneIds() const Q_DECL_OVERRIDE; private: void init(const QByteArray &zoneId); -- cgit v1.2.3 From bc20d794cfddcc34d44a42217aabda1302972cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lisandro=20Dami=C3=A1n=20Nicanor=20P=C3=A9rez=20Meyer?= Date: Thu, 19 Feb 2015 00:07:28 -0300 Subject: Fix typo: properly write endianness. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5240f6eef0eef85cbc6a9107f047f36e97b9a060 Reviewed-by: Thiago Macieira Reviewed-by: Lisandro Damián Nicanor Pérez Meyer Reviewed-by: Dmitry Shachnev --- src/corelib/plugin/qelfparser_p.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp index fcc3820ea7..d93be439e0 100644 --- a/src/corelib/plugin/qelfparser_p.cpp +++ b/src/corelib/plugin/qelfparser_p.cpp @@ -94,7 +94,7 @@ int QElfParser::parse(const char *dataStart, ulong fdlen, const QString &library // endian if (data[5] == 0) { if (lib) - lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("odd endianess")); + lib->errorString = QLibrary::tr("'%1' is an invalid ELF object (%2)").arg(library).arg(QLatin1String("odd endianness")); return Corrupt; } m_endian = (data[5] == 1 ? ElfLittleEndian : ElfBigEndian); -- cgit v1.2.3 From 7e2ef1fd219b57916525c4c5cd5b5750f9fd74fa Mon Sep 17 00:00:00 2001 From: Rafael Roquetto Date: Wed, 11 Feb 2015 16:51:34 -0200 Subject: Remove BlackBerry PlayBook support. Reasons: - the PlayBook NDK is old and its compiler does not keep up with newest C++11 improvements inside Qt code. - the PlayBook NDK diverges considerably from the standard BB10 NDK, making it non-trivial to keep a common codebase. - It's a defunct platform. - Maintenance time is limited. [ChangeLog][Platform Specific Changes] Removed BlackBerry PlayBook support. Change-Id: Ia338aff55f4e4b747ebdecb0e1463a369a656c03 Reviewed-by: Thiago Macieira Reviewed-by: Bernd Weimer Reviewed-by: Rafael Roquetto --- src/corelib/kernel/kernel.pri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/kernel.pri b/src/corelib/kernel/kernel.pri index 87367a9ee7..dabbb2dbbe 100644 --- a/src/corelib/kernel/kernel.pri +++ b/src/corelib/kernel/kernel.pri @@ -175,7 +175,7 @@ blackberry { kernel/qeventdispatcher_blackberry_p.h } -qqnx_pps:!blackberry-playbook { +qqnx_pps { LIBS_PRIVATE += -lpps SOURCES += \ kernel/qppsattribute.cpp \ -- cgit v1.2.3 From 04ec8134e8b001ec2c853a75b581a9d5387c85e6 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Fri, 13 Feb 2015 13:42:28 +0000 Subject: Haiku: Use 'unknown' as QSysInfo::productType() There are no actual products of Haiku, so using 'unknown' (the default) is fine, otherwise the file platform selector would be '+unix/+haiku/+haiku' instead of '+unix/+haiku'. Change-Id: Id7653098e20374885a50c09e2aaac9e6fcfc6efb Reviewed-by: Augustin Cavalier Reviewed-by: Thiago Macieira --- src/corelib/global/qglobal.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 06f9e9080e..712e84185c 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -2529,9 +2529,6 @@ QString QSysInfo::productType() #elif defined(Q_OS_DARWIN) return QStringLiteral("darwin"); -#elif defined(Q_OS_HAIKU) - return QStringLiteral("haiku"); - #elif defined(USE_ETC_OS_RELEASE) // Q_OS_UNIX QUnixOSVersion unixOsVersion; readEtcOsRelease(unixOsVersion); -- cgit v1.2.3 From f7716a0899fba150fcde29f5b03da06dd284c6be Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Mon, 16 Feb 2015 15:00:53 +0000 Subject: Haiku: Extend QStorageInfo implementation Provide the file system type, the name (label) of the volume and the path to the associated device (if available). Change-Id: I7dd0d314d3f757e0f57c8f82beaf8ee21da86167 Reviewed-by: Augustin Cavalier Reviewed-by: Thiago Macieira --- src/corelib/io/qstorageinfo_unix.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp index 667301b516..7e23ac897d 100644 --- a/src/corelib/io/qstorageinfo_unix.cpp +++ b/src/corelib/io/qstorageinfo_unix.cpp @@ -59,6 +59,7 @@ # include # include # include +# include # include #else # include @@ -341,9 +342,18 @@ inline bool QStorageIterator::next() return false; const BPath path(&directory); + + fs_info fsInfo; + memset(&fsInfo, 0, sizeof(fsInfo)); + + if (fs_stat_dev(volume.Device(), &fsInfo) != 0) + return false; + m_rootPath = path.Path(); - m_fileSystemType = QByteArray(); // no public API to access it - m_device = QByteArray::number(static_cast(volume.Device())); + m_fileSystemType = QByteArray(fsInfo.fsh_name); + + const QByteArray deviceName(fsInfo.device_name); + m_device = (deviceName.isEmpty() ? QByteArray::number(qint32(volume.Device())) : deviceName); return true; } @@ -444,6 +454,19 @@ static inline QString retrieveLabel(const QByteArray &device) if (fileInfo.isSymLink() && fileInfo.symLinkTarget().toLocal8Bit() == device) return fileInfo.fileName(); } +#elif defined Q_OS_HAIKU + fs_info fsInfo; + memset(&fsInfo, 0, sizeof(fsInfo)); + + int32 pos = 0; + dev_t dev; + while ((dev = next_dev(&pos)) >= 0) { + if (fs_stat_dev(dev, &fsInfo) != 0) + continue; + + if (qstrcmp(fsInfo.device_name, device.constData()) == 0) + return QString::fromLocal8Bit(fsInfo.volume_name); + } #else Q_UNUSED(device); #endif -- cgit v1.2.3 From de8a34b9bdd3d4fc6f5515e144741bf205adfe6a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 15 Feb 2015 21:01:39 +0100 Subject: QDateTime: drop quotes in QDebug output As requested in review of 1d2efe1f27bedcbaa157ef4e82b8eda33dda46ad. I didn't add a comma in front of the timeSpec() as the other fields aren't separated by commas, either. Change-Id: I54d74b7199ca7e46e28d2ceca22b02205e318c90 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qdatetime.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 191fcf8cfd..aaa639272c 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -4965,7 +4965,8 @@ 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")) + dbg.nospace() << "QDateTime("; + dbg.noquote() << date.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) << ' ' << date.timeSpec(); switch (date.d->m_spec) { case Qt::UTC: -- cgit v1.2.3 From 878cbbcb65f0c872db6c719422d9a426976fa8b2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 15 Feb 2015 21:01:39 +0100 Subject: QDateTime: cache the result of date.timeSpec() in QDebug op<< Saves a couple dozen bytes in text size on optimized AMD64 builds. Change-Id: Iefd9ca05a7b27f240836c1e1e00df569742fcd7f Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qdatetime.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index aaa639272c..eeefea8137 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -4965,10 +4965,11 @@ QDebug operator<<(QDebug dbg, const QTime &time) QDebug operator<<(QDebug dbg, const QDateTime &date) { QDebugStateSaver saver(dbg); + const Qt::TimeSpec ts = date.timeSpec(); dbg.nospace() << "QDateTime("; dbg.noquote() << date.toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz t")) - << ' ' << date.timeSpec(); - switch (date.d->m_spec) { + << ' ' << ts; + switch (ts) { case Qt::UTC: break; case Qt::OffsetFromUTC: -- cgit v1.2.3