From 658c8370e4dd74ee82046799b56947bb3c738b92 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 22 Jan 2016 17:03:48 +0100 Subject: QDateTimeParser: localize variable to avoid shadowing The outer scope it was in had a later clause with its own pos variable. Change-Id: I8d083d3d5935416ef82a78890ed145f02d6d6ded Reviewed-by: Timur Pocheptsov --- src/corelib/tools/qdatetimeparser.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index 5b7bf0d3d4..bda786aa24 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -879,12 +879,12 @@ QDateTimeParser::StateNode QDateTimeParser::parse(QString &input, int &cursorPos State state = Acceptable; QDateTime newCurrentValue; - int pos = 0; bool conflicts = false; const int sectionNodesCount = sectionNodes.size(); QDTPDEBUG << "parse" << input; { + int pos = 0; int year, month, day; currentValue.date().getDate(&year, &month, &day); int year2digits = year % 100; -- cgit v1.2.3 From be94fc445a664fa10ce5ff5ea1e4fbe7d23585e7 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Sun, 13 Nov 2016 15:04:33 +0300 Subject: QString: optimize remove(QChar, Qt::CaseSensitivity) remove(int, int) with O(N) was used in a loop. We had a quadratic complexity. Use erase-remove idiom to fix it. Change-Id: I643a2a75619ec5ea2bf99e48a25f64a7f69ba156 Reviewed-by: Edward Welbourne Reviewed-by: Marc Mutz --- src/corelib/tools/qstring.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 8520bb5740..4262899e02 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -2300,21 +2300,20 @@ QString &QString::remove(const QString &str, Qt::CaseSensitivity cs) */ QString &QString::remove(QChar ch, Qt::CaseSensitivity cs) { - int i = 0; - ushort c = ch.unicode(); - if (cs == Qt::CaseSensitive) { - while (i < d->size) - if (d->data()[i] == ch) - remove(i, 1); - else - i++; - } else { - c = foldCase(c); - while (i < d->size) - if (foldCase(d->data()[i]) == c) - remove(i, 1); - else - i++; + const int idx = indexOf(ch, 0, cs); + if (idx != -1) { + const auto first = begin(); // implicit detach() + auto last = end(); + if (cs == Qt::CaseSensitive) { + last = std::remove(first + idx, last, ch); + } else { + const QChar c = ch.toCaseFolded(); + auto caseInsensEqual = [c](QChar x) { + return c == x.toCaseFolded(); + }; + last = std::remove_if(first + idx, last, caseInsensEqual); + } + resize(last - first); } return *this; } -- cgit v1.2.3 From a4bd635b33d08a4b58fb4db8cefd1e0535fb95eb Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 21 Nov 2016 17:05:49 +0100 Subject: Typo fix in QDateTime::toString() documentation Text that should simply have been naming days of the week used Qt::Sunday rather than the simple day name. Change-Id: I64a3cdacd854c1c9c0fbf2d11826555086d674f4 Reviewed-by: Thiago Macieira --- src/corelib/tools/qdatetime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index 3e29b55666..5f5023e8b5 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -3611,7 +3611,7 @@ QString QDateTime::toString(Qt::DateFormat format) const \li the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses the system locale to localize the name, i.e. QLocale::system(). \row \li dddd - \li the long localized day name (e.g. 'Monday' to 'Qt::Sunday'). + \li the long localized day name (e.g. 'Monday' to 'Sunday'). Uses the system locale to localize the name, i.e. QLocale::system(). \row \li M \li the month as number without a leading zero (1-12) \row \li MM \li the month as number with a leading zero (01-12) -- cgit v1.2.3 From 7c41ced98c3cb5484069c14c45733d3129e7945a Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 2 Feb 2016 17:35:09 +0100 Subject: QDateTimeParser: introduce at least some encapsulation Shuffled its parts to make clear which bits are public, private and protected. QDateTimeEditPrivate makes rather heavy use of the last. Change-Id: Ic5f9d0c5cc85f02e57d3f31e9ac31a17428c5311 Reviewed-by: Timur Pocheptsov --- src/corelib/tools/qdatetimeparser_p.h | 81 ++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 39 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qdatetimeparser_p.h b/src/corelib/tools/qdatetimeparser_p.h index 90c6a8acba..0ac7532aed 100644 --- a/src/corelib/tools/qdatetimeparser_p.h +++ b/src/corelib/tools/qdatetimeparser_p.h @@ -97,14 +97,6 @@ public: none.zeroesAdded = 0; } virtual ~QDateTimeParser() {} - enum AmPmFinder { - Neither = -1, - AM = 0, - PM = 1, - PossibleAM = 2, - PossiblePM = 3, - PossibleBoth = 4 - }; enum Section { NoSection = 0x00000, @@ -180,62 +172,75 @@ public: #ifndef QT_NO_DATESTRING StateNode parse(QString &input, int &cursorPosition, const QDateTime ¤tValue, bool fixup) const; #endif - int sectionMaxSize(int index) const; - int sectionSize(int index) const; - int sectionMaxSize(Section s, int count) const; - int sectionPos(int index) const; - int sectionPos(const SectionNode &sn) const; - - const SectionNode §ionNode(int index) const; - Section sectionType(int index) const; - QString sectionText(int sectionIndex) const; - QString sectionText(const QString &text, int sectionIndex, int index) const; - int getDigit(const QDateTime &dt, int index) const; - bool setDigit(QDateTime &t, int index, int newval) const; - int parseSection(const QDateTime ¤tValue, int sectionIndex, QString &txt, int &cursorPosition, - int index, QDateTimeParser::State &state, int *used = 0) const; - int absoluteMax(int index, const QDateTime &value = QDateTime()) const; - int absoluteMin(int index) const; bool parseFormat(const QString &format); #ifndef QT_NO_DATESTRING bool fromString(const QString &text, QDate *date, QTime *time) const; #endif + enum FieldInfoFlag { + Numeric = 0x01, + FixedWidth = 0x02, + AllowPartial = 0x04, + Fraction = 0x08 + }; + Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag) + + FieldInfo fieldInfo(int index) const; + + void setDefaultLocale(const QLocale &loc) { defaultLocale = loc; } + virtual QString displayText() const { return text; } + +private: + int sectionMaxSize(Section s, int count) const; + QString sectionText(const QString &text, int sectionIndex, int index) const; + int parseSection(const QDateTime ¤tValue, int sectionIndex, QString &txt, int &cursorPosition, + int index, QDateTimeParser::State &state, int *used = 0) const; #ifndef QT_NO_TEXTDATE int findMonth(const QString &str1, int monthstart, int sectionIndex, QString *monthName = 0, int *used = 0) const; int findDay(const QString &str1, int intDaystart, int sectionIndex, QString *dayName = 0, int *used = 0) const; #endif + + enum AmPmFinder { + Neither = -1, + AM = 0, + PM = 1, + PossibleAM = 2, + PossiblePM = 3, + PossibleBoth = 4 + }; AmPmFinder findAmPm(QString &str, int index, int *used = 0) const; bool potentialValue(const QString &str, int min, int max, int index, const QDateTime ¤tValue, int insert) const; - bool skipToNextSection(int section, const QDateTime ¤t, const QString §ionText) const; - QString stateName(State s) const; +protected: // for the benefit of QDateTimeEditPrivate + int sectionSize(int index) const; + int sectionMaxSize(int index) const; + int sectionPos(int index) const; + int sectionPos(const SectionNode &sn) const; - enum FieldInfoFlag { - Numeric = 0x01, - FixedWidth = 0x02, - AllowPartial = 0x04, - Fraction = 0x08 - }; - Q_DECLARE_FLAGS(FieldInfo, FieldInfoFlag) + const SectionNode §ionNode(int index) const; + Section sectionType(int index) const; + QString sectionText(int sectionIndex) const; + int getDigit(const QDateTime &dt, int index) const; + bool setDigit(QDateTime &t, int index, int newval) const; - FieldInfo fieldInfo(int index) const; + int absoluteMax(int index, const QDateTime &value = QDateTime()) const; + int absoluteMin(int index) const; - void setDefaultLocale(const QLocale &loc) { defaultLocale = loc; } + bool skipToNextSection(int section, const QDateTime ¤t, const QString §ionText) const; + QString stateName(State s) const; virtual QDateTime getMinimum() const; virtual QDateTime getMaximum() const; virtual int cursorPosition() const { return -1; } - virtual QString displayText() const { return text; } virtual QString getAmPmText(AmPm ap, Case cs) const; virtual QLocale locale() const { return defaultLocale; } mutable int currentSectionIndex; Sections display; /* - This stores the stores the most recently selected day. + This stores the most recently selected day. It is useful when considering the following scenario: 1. Date is: 31/01/2000 @@ -255,9 +260,7 @@ public: QString displayFormat; QLocale defaultLocale; QVariant::Type parserType; - bool fixday; - Qt::TimeSpec spec; // spec if used by QDateTimeEdit Context context; }; -- cgit v1.2.3 From 40c9e9dc5f31a4063a71e90208b5bf976977b054 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 23 Nov 2016 15:39:57 -0800 Subject: Add a macros for disabling deprecated declaration warnings This is the only warning we disable in a lot of places in Qt 5.8 source code. If other warnings become common, we can add macros for them too. Change-Id: Iaeecaffe26af4535b416fffd1489d1968e29c52a Reviewed-by: Oswald Buddenhagen Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qalgorithms.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index 38753a6726..303374b06d 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -48,8 +48,7 @@ QT_BEGIN_NAMESPACE QT_WARNING_PUSH -QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") -QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") +QT_WARNING_DISABLE_DEPRECATED /* Warning: The contents of QAlgorithmsPrivate is not a part of the public Qt API -- cgit v1.2.3 From 7eb4be9db89d40ea2cc090e7a562bdd588708607 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Sun, 13 Nov 2016 16:19:55 +0300 Subject: QStringRef: de-duplicate lastIndexOf code Change-Id: Id6d804b2ab4c9c763d7ec9cb66c255ed0b4f785d Reviewed-by: Thiago Macieira --- src/corelib/tools/qstring.cpp | 77 ++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 37 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 4262899e02..eef375fe72 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -3260,6 +3260,23 @@ static int lastIndexOfHelper(const ushort *haystack, int from, const ushort *nee return -1; } +static inline int lastIndexOfHelper( + const QStringRef &haystack, int from, const QStringRef &needle, Qt::CaseSensitivity cs) +{ + return lastIndexOfHelper(reinterpret_cast(haystack.unicode()), from, + reinterpret_cast(needle.unicode()), needle.size(), cs); +} + +static inline int lastIndexOfHelper( + const QStringRef &haystack, int from, QLatin1String needle, Qt::CaseSensitivity cs) +{ + const int size = needle.size(); + QVarLengthArray s(size); + qt_from_latin1(s.data(), needle.latin1(), size); + return lastIndexOfHelper(reinterpret_cast(haystack.unicode()), from, + s.data(), size, cs); +} + /*! Returns the index position of the last occurrence of the string \a str in this string, searching backward from index position \a @@ -9816,6 +9833,27 @@ int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const return qt_last_index_of(unicode(), size(), ch, from, cs); } +template +static int last_index_of_impl(const QStringRef &haystack, int from, const T &needle, Qt::CaseSensitivity cs) +{ + const int sl = needle.size(); + if (sl == 1) + return haystack.lastIndexOf(needle.at(0), from, cs); + + const int l = haystack.size(); + if (from < 0) + from += l; + int delta = l - sl; + if (from == l && sl == 0) + return from; + if (uint(from) >= uint(l) || delta < 0) + return -1; + if (from > delta) + from = delta; + + return lastIndexOfHelper(haystack, from, needle, cs); +} + /*! \since 4.8 \overload lastIndexOf() @@ -9833,25 +9871,7 @@ int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const */ int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const { - const int sl = str.size(); - if (sl == 1) - return lastIndexOf(str.at(0), from, cs); - - const int l = size(); - if (from < 0) - from += l; - int delta = l - sl; - if (from == l && sl == 0) - return from; - if (uint(from) >= uint(l) || delta < 0) - return -1; - if (from > delta) - from = delta; - - QVarLengthArray s(sl); - qt_from_latin1(s.data(), str.latin1(), sl); - - return lastIndexOfHelper(reinterpret_cast(unicode()), from, s.data(), sl, cs); + return last_index_of_impl(*this, from, str, cs); } /*! @@ -9871,24 +9891,7 @@ int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) */ int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const { - const int sl = str.size(); - if (sl == 1) - return lastIndexOf(str.at(0), from, cs); - - const int l = size(); - if (from < 0) - from += l; - int delta = l - sl; - if (from == l && sl == 0) - return from; - if (uint(from) >= uint(l) || delta < 0) - return -1; - if (from > delta) - from = delta; - - return lastIndexOfHelper(reinterpret_cast(unicode()), from, - reinterpret_cast(str.unicode()), - str.size(), cs); + return last_index_of_impl(*this, from, str, cs); } /*! -- cgit v1.2.3 From a103992f49045323a3aaa4970eb1ee5f65a378dd Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 24 Nov 2016 12:17:55 +0100 Subject: Fixed build using Visual Studio 2017 As _BitScanForward and friends are not marked constexpr in Visual Studio, functions using these may not be marked either. Task-number: QTBUG-57086 Change-Id: I29cfa4459580b5740f1011e7f39309844518ce03 Reviewed-by: Thiago Macieira Reviewed-by: Erik Verbruggen --- src/corelib/tools/qalgorithms.h | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qalgorithms.h b/src/corelib/tools/qalgorithms.h index 303374b06d..7e846956f5 100644 --- a/src/corelib/tools/qalgorithms.h +++ b/src/corelib/tools/qalgorithms.h @@ -589,15 +589,16 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NO return __builtin_popcountll(v); } #elif defined(Q_CC_MSVC) && !defined(Q_OS_WINCE) && !defined(Q_PROCESSOR_ARM) +#define QT_POPCOUNT_CONSTEXPR #define QT_HAS_BUILTIN_CTZ -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctz(quint32 val) +Q_ALWAYS_INLINE unsigned long qt_builtin_ctz(quint32 val) { unsigned long result; _BitScanForward(&result, val); return result; } #define QT_HAS_BUILTIN_CLZ -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clz(quint32 val) +Q_ALWAYS_INLINE unsigned long qt_builtin_clz(quint32 val) { unsigned long result; _BitScanReverse(&result, val); @@ -610,7 +611,7 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clz(quint32 val) #if Q_PROCESSOR_WORDSIZE == 8 // These are only defined for 64bit builds. #define QT_HAS_BUILTIN_CTZLL -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctzll(quint64 val) +Q_ALWAYS_INLINE unsigned long qt_builtin_ctzll(quint64 val) { unsigned long result; _BitScanForward64(&result, val); @@ -618,7 +619,7 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_ctzll(quint64 val) } // MSVC calls it _BitScanReverse and returns the carry flag, which we don't need #define QT_HAS_BUILTIN_CLZLL -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clzll(quint64 val) +Q_ALWAYS_INLINE unsigned long qt_builtin_clzll(quint64 val) { unsigned long result; _BitScanReverse64(&result, val); @@ -628,31 +629,31 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE unsigned long qt_builtin_clzll(quint64 val) } #endif // MSVC 64bit # define QT_HAS_BUILTIN_CTZS -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_ctzs(quint16 v) Q_DECL_NOTHROW { return qt_builtin_ctz(v); } #define QT_HAS_BUILTIN_CLZS -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_clzs(quint16 v) Q_DECL_NOTHROW { return qt_builtin_clz(v) - 16U; } #define QALGORITHMS_USE_BUILTIN_POPCOUNT -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcount(quint32 v) Q_DECL_NOTHROW { return __popcnt(v); } -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcount(quint8 v) Q_DECL_NOTHROW { return __popcnt16(v); } -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcount(quint16 v) Q_DECL_NOTHROW { return __popcnt16(v); } #if Q_PROCESSOR_WORDSIZE == 8 #define QALGORITHMS_USE_BUILTIN_POPCOUNTLL -Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW +Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NOTHROW { return __popcnt64(v); } @@ -660,9 +661,13 @@ Q_DECL_CONSTEXPR Q_ALWAYS_INLINE uint qt_builtin_popcountll(quint64 v) Q_DECL_NO #endif // MSVC #endif // QT_HAS_CONSTEXPR_BUILTINS +#ifndef QT_POPCOUNT_CONSTEXPR +#define QT_POPCOUNT_CONSTEXPR Q_DECL_CONSTEXPR +#endif + } //namespace QAlgorithmsPrivate -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint32 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint32 v) Q_DECL_NOTHROW { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT return QAlgorithmsPrivate::qt_builtin_popcount(v); @@ -675,7 +680,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint32 v) Q #endif } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint8 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint8 v) Q_DECL_NOTHROW { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT return QAlgorithmsPrivate::qt_builtin_popcount(v); @@ -685,7 +690,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint8 v) Q_ #endif } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint16 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint16 v) Q_DECL_NOTHROW { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNT return QAlgorithmsPrivate::qt_builtin_popcount(v); @@ -696,7 +701,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint16 v) Q #endif } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint64 v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(quint64 v) Q_DECL_NOTHROW { #ifdef QALGORITHMS_USE_BUILTIN_POPCOUNTLL return QAlgorithmsPrivate::qt_builtin_popcountll(v); @@ -711,7 +716,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(quint64 v) Q #endif } -Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(long unsigned int v) Q_DECL_NOTHROW +Q_DECL_CONST_FUNCTION QT_POPCOUNT_CONSTEXPR inline uint qPopulationCount(long unsigned int v) Q_DECL_NOTHROW { return qPopulationCount(static_cast(v)); } @@ -719,6 +724,7 @@ Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qPopulationCount(long unsigne #if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) #undef QALGORITHMS_USE_BUILTIN_POPCOUNT #endif +#undef QT_POPCOUNT_CONSTEXPR Q_DECL_RELAXED_CONSTEXPR inline uint qCountTrailingZeroBits(quint32 v) Q_DECL_NOTHROW { -- cgit v1.2.3 From e3555fe9705a44072a05b95cca36579745e14125 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 18 Nov 2016 13:32:19 +0100 Subject: Properly use QT_CONFIG macro to check for ICU And remove the QT_USE_ICU define. Change-Id: I8134ee18af7c90ed7070926ca31b3a57b3ec37dd Reviewed-by: Oswald Buddenhagen --- src/corelib/tools/qcollator_p.h | 6 +++--- src/corelib/tools/qlocale.cpp | 4 ++-- src/corelib/tools/qlocale_p.h | 2 +- src/corelib/tools/qstring.cpp | 4 ++-- src/corelib/tools/qtimezone.cpp | 12 ++++++------ src/corelib/tools/qtimezoneprivate.cpp | 2 +- src/corelib/tools/qtimezoneprivate_p.h | 12 ++++++------ src/corelib/tools/qtimezoneprivate_tz.cpp | 20 ++++++++++---------- src/corelib/tools/tools.pri | 1 - 9 files changed, 31 insertions(+), 32 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qcollator_p.h b/src/corelib/tools/qcollator_p.h index fbbce00676..423ba0325a 100644 --- a/src/corelib/tools/qcollator_p.h +++ b/src/corelib/tools/qcollator_p.h @@ -55,7 +55,7 @@ #include #include "qcollator.h" #include -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) #include #elif defined(Q_OS_OSX) #include @@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) typedef UCollator *CollatorType; typedef QByteArray CollatorKeyType; @@ -90,7 +90,7 @@ class Q_CORE_EXPORT QCollatorPrivate public: QAtomicInt ref; QLocale locale; -#if defined(Q_OS_WIN) && !defined(QT_USE_ICU) +#if defined(Q_OS_WIN) && !QT_CONFIG(icu) #ifdef USE_COMPARESTRINGEX QString localeName; #else diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 847fc2d55e..f499681ca9 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -2431,7 +2431,7 @@ Qt::LayoutDirection QLocale::textDirection() const */ QString QLocale::toUpper(const QString &str) const { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) bool ok = true; QString result = QIcu::toUpper(d->bcp47Name('_'), str, &ok); if (ok) @@ -2455,7 +2455,7 @@ QString QLocale::toUpper(const QString &str) const */ QString QLocale::toLower(const QString &str) const { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) bool ok = true; const QString result = QIcu::toLower(d->bcp47Name('_'), str, &ok); if (ok) diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index c83c9d3333..20eff8fd64 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -134,7 +134,7 @@ Q_DECLARE_TYPEINFO(QSystemLocale::QueryType, Q_PRIMITIVE_TYPE); Q_DECLARE_TYPEINFO(QSystemLocale::CurrencyToStringArgument, Q_MOVABLE_TYPE); #endif -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) namespace QIcu { QString toUpper(const QByteArray &localeId, const QString &str, bool *ok); QString toLower(const QByteArray &localeId, const QString &str, bool *ok); diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index eef375fe72..8888eced87 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -5575,7 +5575,7 @@ int QString::localeAwareCompare(const QString &other) const return localeAwareCompare_helper(constData(), length(), other.constData(), other.length()); } -#if defined(QT_USE_ICU) && !defined(Q_OS_WIN32) && !defined(Q_OS_DARWIN) +#if QT_CONFIG(icu) && !defined(Q_OS_WIN32) && !defined(Q_OS_DARWIN) Q_GLOBAL_STATIC(QThreadStorage, defaultCollator) #endif @@ -5621,7 +5621,7 @@ int QString::localeAwareCompare_helper(const QChar *data1, int length1, CFRelease(thisString); CFRelease(otherString); return result; -#elif defined(QT_USE_ICU) +#elif QT_CONFIG(icu) if (!defaultCollator()->hasLocalData()) defaultCollator()->setLocalData(QCollator()); return defaultCollator()->localData().compare(data1, length1, data2, length2); diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp index e423d9af0c..359c2d0bdb 100644 --- a/src/corelib/tools/qtimezone.cpp +++ b/src/corelib/tools/qtimezone.cpp @@ -54,11 +54,11 @@ QT_BEGIN_NAMESPACE static QTimeZonePrivate *newBackendTimeZone() { #ifdef QT_NO_SYSTEMLOCALE -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) return new QIcuTimeZonePrivate(); #else return new QUtcTimeZonePrivate(); -#endif // QT_USE_ICU +#endif #else #if defined Q_OS_MAC return new QMacTimeZonePrivate(); @@ -69,7 +69,7 @@ static QTimeZonePrivate *newBackendTimeZone() // Registry based timezone backend not available on WinRT #elif defined Q_OS_WIN return new QWinTimeZonePrivate(); -#elif defined QT_USE_ICU +#elif QT_CONFIG(icu) return new QIcuTimeZonePrivate(); #else return new QUtcTimeZonePrivate(); @@ -81,11 +81,11 @@ static QTimeZonePrivate *newBackendTimeZone() static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId) { #ifdef QT_NO_SYSTEMLOCALE -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) return new QIcuTimeZonePrivate(ianaId); #else return new QUtcTimeZonePrivate(ianaId); -#endif // QT_USE_ICU +#endif #else #if defined Q_OS_MAC return new QMacTimeZonePrivate(ianaId); @@ -96,7 +96,7 @@ static QTimeZonePrivate *newBackendTimeZone(const QByteArray &ianaId) // Registry based timezone backend not available on WinRT #elif defined Q_OS_WIN return new QWinTimeZonePrivate(ianaId); -#elif defined QT_USE_ICU +#elif QT_CONFIG(icu) return new QIcuTimeZonePrivate(ianaId); #else return new QUtcTimeZonePrivate(ianaId); diff --git a/src/corelib/tools/qtimezoneprivate.cpp b/src/corelib/tools/qtimezoneprivate.cpp index 56da197542..2ff03eddec 100644 --- a/src/corelib/tools/qtimezoneprivate.cpp +++ b/src/corelib/tools/qtimezoneprivate.cpp @@ -590,7 +590,7 @@ template<> QTimeZonePrivate *QSharedDataPointer::clone() } /* - UTC Offset implementation, used when QT_NO_SYSTEMLOCALE set and QT_USE_ICU not set, + UTC Offset implementation, used when QT_NO_SYSTEMLOCALE set and ICU is not being used, or for QDateTimes with a Qt:Spec of Qt::OffsetFromUtc. */ diff --git a/src/corelib/tools/qtimezoneprivate_p.h b/src/corelib/tools/qtimezoneprivate_p.h index d7fbb12344..d06784b0f9 100644 --- a/src/corelib/tools/qtimezoneprivate_p.h +++ b/src/corelib/tools/qtimezoneprivate_p.h @@ -56,9 +56,9 @@ #include "qlocale_p.h" #include "qvector.h" -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) #include -#endif // QT_USE_ICU +#endif #ifdef Q_OS_MAC #ifdef __OBJC__ @@ -227,7 +227,7 @@ private: int m_offsetFromUtc; }; -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) class Q_AUTOTEST_EXPORT QIcuTimeZonePrivate Q_DECL_FINAL : public QTimeZonePrivate { public: @@ -268,7 +268,7 @@ private: UCalendar *m_ucal; }; -#endif // QT_USE_ICU +#endif #if defined Q_OS_UNIX && !defined Q_OS_MAC && !defined Q_OS_ANDROID struct QTzTransitionTime @@ -337,9 +337,9 @@ private: QVector m_tranTimes; QVector m_tranRules; QList m_abbreviations; -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) mutable QSharedDataPointer m_icu; -#endif // QT_USE_ICU +#endif QByteArray m_posixRule; }; #endif // Q_OS_UNIX diff --git a/src/corelib/tools/qtimezoneprivate_tz.cpp b/src/corelib/tools/qtimezoneprivate_tz.cpp index 96d04df0e2..10b61c3a40 100644 --- a/src/corelib/tools/qtimezoneprivate_tz.cpp +++ b/src/corelib/tools/qtimezoneprivate_tz.cpp @@ -598,18 +598,18 @@ static QVector calculatePosixTransitions(const QByteArra // Create the system default time zone QTzTimeZonePrivate::QTzTimeZonePrivate() -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) : m_icu(0) -#endif // QT_USE_ICU +#endif { init(systemTimeZoneId()); } // Create a named time zone QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) : m_icu(0) -#endif // QT_USE_ICU +#endif { init(ianaId); } @@ -617,9 +617,9 @@ QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) QTzTimeZonePrivate::QTzTimeZonePrivate(const QTzTimeZonePrivate &other) : QTimeZonePrivate(other), m_tranTimes(other.m_tranTimes), m_tranRules(other.m_tranRules), m_abbreviations(other.m_abbreviations), -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) m_icu(other.m_icu), -#endif // QT_USE_ICU +#endif m_posixRule(other.m_posixRule) { } @@ -778,7 +778,7 @@ QString QTzTimeZonePrivate::displayName(qint64 atMSecsSinceEpoch, QTimeZone::NameType nameType, const QLocale &locale) const { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) if (!m_icu) m_icu = new QIcuTimeZonePrivate(m_id); // TODO small risk may not match if tran times differ due to outdated files @@ -788,7 +788,7 @@ QString QTzTimeZonePrivate::displayName(qint64 atMSecsSinceEpoch, #else Q_UNUSED(nameType) Q_UNUSED(locale) -#endif // QT_USE_ICU +#endif return abbreviation(atMSecsSinceEpoch); } @@ -796,7 +796,7 @@ QString QTzTimeZonePrivate::displayName(QTimeZone::TimeType timeType, QTimeZone::NameType nameType, const QLocale &locale) const { -#ifdef QT_USE_ICU +#if QT_CONFIG(icu) if (!m_icu) m_icu = new QIcuTimeZonePrivate(m_id); // TODO small risk may not match if tran times differ due to outdated files @@ -807,7 +807,7 @@ QString QTzTimeZonePrivate::displayName(QTimeZone::TimeType timeType, Q_UNUSED(timeType) Q_UNUSED(nameType) Q_UNUSED(locale) -#endif // QT_USE_ICU +#endif // If no ICU available then have to use abbreviations instead // Abbreviations don't have GenericTime if (timeType == QTimeZone::GenericTime) diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index fb80bbd6b8..fa8e07abbc 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -144,7 +144,6 @@ qtConfig(icu) { SOURCES += tools/qlocale_icu.cpp \ tools/qcollator_icu.cpp - DEFINES += QT_USE_ICU } else: win32 { SOURCES += tools/qcollator_win.cpp } else: macx { -- cgit v1.2.3 From 5ac33fff0f38ee8a363f8e2dc5a8306c05af0db6 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Tue, 29 Nov 2016 13:58:56 +0100 Subject: QCommandLineOption: Remove excess close parenthesis from a warning Change-Id: Iff197a2a00b686ad2d29a1e156389bec4639f3c0 Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira --- src/corelib/tools/qcommandlineoption.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qcommandlineoption.h b/src/corelib/tools/qcommandlineoption.h index 4dcae03ad9..276be042de 100644 --- a/src/corelib/tools/qcommandlineoption.h +++ b/src/corelib/tools/qcommandlineoption.h @@ -94,7 +94,7 @@ public: void setFlags(Flags aflags); #if QT_DEPRECATED_SINCE(5, 8) - QT_DEPRECATED_X("Use setFlags() with HiddenFromHelp)") + QT_DEPRECATED_X("Use setFlags() with HiddenFromHelp") void setHidden(bool hidden); QT_DEPRECATED_X("Use flags() and HiddenFromHelp") bool isHidden() const; -- cgit v1.2.3 From b0c321a8db7b75d740d968c6a583473600faf990 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 22 Nov 2016 14:52:18 -0800 Subject: Don't crash on QVLA construction from an empty std::initializer_list The C++ standard says in [support.initlist.access]/1: constexpr const E* begin() const noexcept; Returns: A pointer to the beginning of the array. If size() == 0 the values of begin() and end() are unspecified but they shall be identical. So we can't assume it's non-null. I didn't want to remove the Q_ASSERT, so passing a non-null pointer to append() remains required. This patch simply won't call append() if the initializer list is empty. This was already tested, but the failure is with a compiler that is not part of the Qt CI. Task-number: QTBUG-57277 Change-Id: Iaeecaffe26af4535b416fffd1489806872b412ee Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/tools/qvarlengtharray.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index c3ac104399..1530299303 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -76,7 +76,8 @@ public: QVarLengthArray(std::initializer_list args) : a(Prealloc), s(0), ptr(reinterpret_cast(array)) { - append(args.begin(), args.size()); + if (args.size()) + append(args.begin(), args.size()); } #endif -- cgit v1.2.3 From 1da70af724e16caa6ce175630f13434fcded512b Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 1 Nov 2016 08:40:20 +0000 Subject: QMap: use std::less for defining an order between pointers Reinterpret_cast()ing a pointer to a suitably sized integer is not guaranteed to always give the same result for the same pointer (!). Therefore the resulting integers are not comparable in a meaningful way. std::less is supposed to be used to compare arbitrary pointers, so use it. (Hopefully and reasonably, under the hood std::less does exactly what we were doing, so this isn't BiC.) Change-Id: I9960b3d6e35657fe7a25b842054f5d338280e850 Reviewed-by: Thiago Macieira --- src/corelib/tools/qmap.cpp | 4 +++- src/corelib/tools/qmap.h | 11 ++++------- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 406eb31923..94ed47f898 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -399,7 +399,9 @@ void QMapDataBase::freeData(QMapDataBase *d) With QMap, the items are always sorted by key. \li The key type of a QHash must provide operator==() and a global qHash(Key) function. The key type of a QMap must provide - operator<() specifying a total order. + operator<() specifying a total order. Since Qt 5.8.1 it is also safe + to use a pointer type as key, even if the underlying operator<() + does not provide a total order. \endlist Here's an example QMap with QString keys and \c int values: diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 96ce787446..3f4f034b4e 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -51,6 +51,7 @@ #include #include +#include #ifdef Q_COMPILER_INITIALIZER_LISTS #include @@ -61,11 +62,8 @@ QT_BEGIN_NAMESPACE /* QMap uses qMapLessThanKey() to compare keys. The default implementation uses operator<(). For pointer types, - qMapLessThanKey() casts the pointers to integers before it - compares them, because operator<() is undefined on pointers - that come from different memory blocks. (In practice, this - is only a problem when running a program such as - BoundsChecker.) + qMapLessThanKey() uses std::less (because operator<() on + pointers can be used only between pointers in the same array). */ template inline bool qMapLessThanKey(const Key &key1, const Key &key2) @@ -75,8 +73,7 @@ template inline bool qMapLessThanKey(const Key &key1, const Key &key template inline bool qMapLessThanKey(const Ptr *key1, const Ptr *key2) { - Q_STATIC_ASSERT(sizeof(quintptr) == sizeof(const Ptr *)); - return quintptr(key1) < quintptr(key2); + return std::less()(key1, key2); } struct QMapDataBase; -- cgit v1.2.3