From 4577026397ac15bead5ddcbda4b0a57bae831acb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 12:01:48 +0100 Subject: QTimeZone: add member-swap This is customary for Qt value types these days. Change-Id: If5374c2595a904337eaef4afc08cdc993229ac25 Reviewed-by: John Layt Reviewed-by: Lars Knoll --- src/corelib/tools/qtimezone.cpp | 7 +++++++ src/corelib/tools/qtimezone.h | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp index b6196d99e5..6fe42ab45e 100644 --- a/src/corelib/tools/qtimezone.cpp +++ b/src/corelib/tools/qtimezone.cpp @@ -422,6 +422,13 @@ QTimeZone &QTimeZone::operator=(const QTimeZone &other) return *this; } +/* + \fn void QTimeZone::swap(QTimeZone &other) + + Swaps this timezone with \a other. This function is very fast and + never fails. +*/ + /*! \fn QTimeZone &QTimeZone::operator=(QTimeZone &&other) diff --git a/src/corelib/tools/qtimezone.h b/src/corelib/tools/qtimezone.h index 1a6a923cf4..7fb4a885ef 100644 --- a/src/corelib/tools/qtimezone.h +++ b/src/corelib/tools/qtimezone.h @@ -87,9 +87,12 @@ public: QTimeZone &operator=(const QTimeZone &other); #ifdef Q_COMPILER_RVALUE_REFS - QTimeZone &operator=(QTimeZone &&other) { std::swap(d, other.d); return *this; } + QTimeZone &operator=(QTimeZone &&other) { swap(other); return *this; } #endif + void swap(QTimeZone &other) + { d.swap(other.d); } + bool operator==(const QTimeZone &other) const; bool operator!=(const QTimeZone &other) const; -- cgit v1.2.3 From 81ef7f685710dc83bc42c4eb81d71140e89bea40 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 12:03:07 +0100 Subject: QTimeZone: declare as shared This enables specialisations of (std and q) swap using member-swap and declares the types movable for efficient use in Qt containers, and QList in particular. This is a binary-incompatible change, so cannot wait for 5.2.1. Change-Id: I431315e148b95f82dc3d4471c57ef729539dca9f Reviewed-by: John Layt Reviewed-by: Lars Knoll --- src/corelib/tools/qtimezone.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qtimezone.h b/src/corelib/tools/qtimezone.h index 7fb4a885ef..3f0d1ee9e7 100644 --- a/src/corelib/tools/qtimezone.h +++ b/src/corelib/tools/qtimezone.h @@ -152,6 +152,7 @@ private: }; Q_DECLARE_TYPEINFO(QTimeZone::OffsetData, Q_MOVABLE_TYPE); +Q_DECLARE_SHARED(QTimeZone) #ifndef QT_NO_DATASTREAM Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds, const QTimeZone &tz); -- cgit v1.2.3 From 9e78ab458714cb143703ded378be9e84380c2c98 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 12:03:44 +0100 Subject: Doc: remove superfluous \since 5.2 The whole QTimeZone class is \since 5.2. Change-Id: I681b924b534f2f75315b2eaf506aaa7d9590efa1 Reviewed-by: John Layt Reviewed-by: Lars Knoll --- src/corelib/tools/qtimezone.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qtimezone.cpp b/src/corelib/tools/qtimezone.cpp index 6fe42ab45e..9288dc7756 100644 --- a/src/corelib/tools/qtimezone.cpp +++ b/src/corelib/tools/qtimezone.cpp @@ -434,8 +434,6 @@ QTimeZone &QTimeZone::operator=(const QTimeZone &other) Move-assigns \a other to this QTimeZone instance, transferring the ownership of the managed pointer to this instance. - - \since 5.2 */ /*! -- cgit v1.2.3 From 6128f4efb42dec892ce057d92832adc820114c60 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 12:07:08 +0100 Subject: QTimeZone: mark ctors as explicit An int is not a proper representation for a QTimeZone, so don't provide an implicit conversion from it. OTOH, {QByteArray, int, QString, QString} _does_ nicely represent a QTimeZone, so explicitly state the implicitness of that constructor so {}-init continues to work in C++11. Change-Id: I865a6b38b8ab3c577625b7b08efbfc98914abfbe Reviewed-by: John Layt Reviewed-by: Lars Knoll --- src/corelib/tools/qtimezone.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qtimezone.h b/src/corelib/tools/qtimezone.h index 3f0d1ee9e7..cbc4f3e4ad 100644 --- a/src/corelib/tools/qtimezone.h +++ b/src/corelib/tools/qtimezone.h @@ -78,8 +78,8 @@ public: QTimeZone(); explicit QTimeZone(const QByteArray &olsenId); - QTimeZone(int offsetSeconds); - QTimeZone(const QByteArray &zoneId, int offsetSeconds, const QString &name, + explicit QTimeZone(int offsetSeconds); + /*implicit*/ QTimeZone(const QByteArray &zoneId, int offsetSeconds, const QString &name, const QString &abbreviation, QLocale::Country country = QLocale::AnyCountry, const QString &comment = QString()); QTimeZone(const QTimeZone &other); -- cgit v1.2.3 From 127c18ff1100a9fb8559ca651dbc03ff1f8eabbd Mon Sep 17 00:00:00 2001 From: Marcel Krems Date: Sun, 10 Nov 2013 04:05:34 +0100 Subject: Doc: Add missing \since 5.2 to QMap::first/last{,Key} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I04b356bfdd2298dccb174ac7cc83d54a3fbcdc02 Reviewed-by: Thorbjørn Lund Martsum --- src/corelib/tools/qmap.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp index 9aebbb7b3c..22d744f869 100644 --- a/src/corelib/tools/qmap.cpp +++ b/src/corelib/tools/qmap.cpp @@ -897,6 +897,7 @@ void QMapDataBase::freeData(QMapDataBase *d) */ /*! \fn const Key &QMap::firstKey() const + \since 5.2 Returns a reference to the smallest key in the map. This function assumes that the map is not empty. @@ -907,6 +908,7 @@ void QMapDataBase::freeData(QMapDataBase *d) */ /*! \fn const Key &QMap::lastKey() const + \since 5.2 Returns a reference to the largest key in the map. This function assumes that the map is not empty. @@ -917,6 +919,7 @@ void QMapDataBase::freeData(QMapDataBase *d) */ /*! \fn T &QMap::first() + \since 5.2 Returns a reference to the first value in the map, that is the value mapped to the smallest key. This function assumes that the map is not empty. @@ -927,11 +930,13 @@ void QMapDataBase::freeData(QMapDataBase *d) */ /*! \fn const T &QMap::first() const + \since 5.2 \overload */ /*! \fn T &QMap::last() + \since 5.2 Returns a reference to the last value in the map, that is the value mapped to the largest key. This function assumes that the map is not empty. @@ -942,6 +947,7 @@ void QMapDataBase::freeData(QMapDataBase *d) */ /*! \fn const T &QMap::last() const + \since 5.2 \overload */ -- cgit v1.2.3 From 38e90ad2b3cff1220c9214290b4c4fed9dd39bd5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 12 Nov 2013 11:17:05 +0100 Subject: qcompilerdetection.h: add Q_COMPILER_UNIFORM_INIT Up to now, the feature classe Uniform Initialization was subsumed by the Q_COMPILER_INITIALIZER_LISTS flag together with support for std::initializer_list. This caused at least two problems: 1. On QNX, the standard libray does not ship , even though the compiler (a GCC 4.6, IIRC) supports it. But since there was only one Q_COMPILER flag for both, support for the compiler-only part of the feature had to be disabled, too. 2. MSVC 2013 supports initializer lists, but has a bug that renders full uniform initialization support, as required for QUuid, useless. By splitting the feature into two, we can separate them better, and do so in QUuid, which is the only class that currently takes advantage of uniform initialization (to provide constexpr constructors). Since Q_COMPILER_INITIALIZER_LISTS worked as a flag for uniform initialization so far, with the two known exceptions above, UNIFORM_INIT is defined whenever INITIALIZER_LIST is, except that I don't revert UNIFORM_INIT on QNX as I do for INITIALIZER_LISTS and that I expect the MSVC 2013 features to set INITIALIZER_LIST, but not UNIFORM_INIT. Task-number: QTBUG-34705 Change-Id: I81916e950a0f3aab3de7977e0326d2de3d31b14c Reviewed-by: Yuchen Deng Reviewed-by: Thiago Macieira --- src/corelib/global/qcompilerdetection.h | 7 ++++++- src/corelib/plugin/quuid.h | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index d02e4cf199..f23478d75c 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -465,6 +465,7 @@ * N2659 Q_COMPILER_THREAD_LOCAL * N2765 Q_COMPILER_UDL * N2442 Q_COMPILER_UNICODE_STRINGS + * N2640 Q_COMPILER_UNIFORM_INIT * N2544 Q_COMPILER_UNRESTRICTED_UNIONS * N1653 Q_COMPILER_VARIADIC_MACROS * N2242 N2555 Q_COMPILER_VARIADIC_TEMPLATES @@ -502,6 +503,7 @@ // constexpr support is only partial //# define Q_COMPILER_CONSTEXPR # define Q_COMPILER_INITIALIZER_LISTS +# define Q_COMPILER_UNIFORM_INIT # define Q_COMPILER_NOEXCEPT # endif # if __INTEL_COMPILER >= 1400 @@ -573,6 +575,7 @@ # endif # if __has_feature(cxx_generalized_initializers) # define Q_COMPILER_INITIALIZER_LISTS +# define Q_COMPILER_UNIFORM_INIT /* both covered by this feature macro, according to docs */ # endif # if __has_feature(cxx_lambdas) # define Q_COMPILER_LAMBDA @@ -645,6 +648,7 @@ # define Q_COMPILER_DELETE_MEMBERS # define Q_COMPILER_EXTERN_TEMPLATES # define Q_COMPILER_INITIALIZER_LISTS +# define Q_COMPILER_UNIFORM_INIT # define Q_COMPILER_UNICODE_STRINGS # define Q_COMPILER_VARIADIC_TEMPLATES # endif @@ -718,8 +722,9 @@ # define Q_COMPILER_DECLTYPE # define Q_COMPILER_RVALUE_REFS # define Q_COMPILER_STATIC_ASSERT -// MSVC has std::initilizer_list, but does not support the braces initialization +// MSVC's library has std::initilizer_list, but the compiler does not support the braces initialization //# define Q_COMPILER_INITIALIZER_LISTS +//# define Q_COMPILER_UNIFORM_INIT # endif # if _MSC_VER >= 1700 /* C++11 features supported in VC11 = VC2012: */ diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h index 31b9890351..a0d2923bed 100644 --- a/src/corelib/plugin/quuid.h +++ b/src/corelib/plugin/quuid.h @@ -82,7 +82,7 @@ public: Sha1 = 5 // 0 1 0 1 }; -#if defined(Q_COMPILER_INITIALIZER_LISTS) && !defined(Q_QDOC) +#if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_QDOC) Q_DECL_CONSTEXPR QUuid() : data1(0), data2(0), data3(0), data4{0,0,0,0,0,0,0,0} {} Q_DECL_CONSTEXPR QUuid(uint l, ushort w1, ushort w2, uchar b1, uchar b2, uchar b3, @@ -147,7 +147,7 @@ public: #if defined(Q_OS_WIN) // On Windows we have a type GUID that is used by the platform API, so we // provide convenience operators to cast from and to this type. -#if defined(Q_COMPILER_INITIALIZER_LISTS) && !defined(Q_QDOC) +#if defined(Q_COMPILER_UNIFORM_INIT) && !defined(Q_QDOC) Q_DECL_CONSTEXPR QUuid(const GUID &guid) : data1(guid.Data1), data2(guid.Data2), data3(guid.Data3), data4{guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], -- cgit v1.2.3 From 7d72516b52b20b0782d972224a55a43e74b8ae5a Mon Sep 17 00:00:00 2001 From: Alan Alpert <416365416c@gmail.com> Date: Fri, 13 Sep 2013 13:57:21 -0700 Subject: Change platform selectors to match qmake selectors Previously matched Qt.platform.os, however that can only provide one string. Multiple selectors can be present at once, so we can provide both unix and linux instead of having to pick the most specialized one. Task-number: QTBUG-34796 Change-Id: I219517d740fa7385e923a9e09cb7e241378fbaee Reviewed-by: David Faure --- src/corelib/io/qfileselector.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qfileselector.cpp b/src/corelib/io/qfileselector.cpp index d67ea80e51..eed9e8870a 100644 --- a/src/corelib/io/qfileselector.cpp +++ b/src/corelib/io/qfileselector.cpp @@ -348,22 +348,28 @@ void QFileSelectorPrivate::updateSelectors() QStringList QFileSelectorPrivate::platformSelectors() { QStringList ret; -#if defined(Q_OS_LINUX_ANDROID) +#if defined(Q_OS_WIN) + ret << QStringLiteral("windows"); +# if defined(Q_OS_WINCE) + ret << QStringLiteral("wince"); +# endif +#elif defined(Q_OS_UNIX) + ret << QStringLiteral("unix"); +# if defined(Q_OS_LINUX_ANDROID) ret << QStringLiteral("android"); -#elif defined(Q_OS_BLACKBERRY) +# elif defined(Q_OS_BLACKBERRY) ret << QStringLiteral("blackberry"); -#elif defined(Q_OS_IOS) +# elif defined(Q_OS_IOS) ret << QStringLiteral("ios"); -#elif defined(Q_OS_WINCE) - ret << QStringLiteral("wince"); -#elif defined(Q_OS_WIN) - ret << QStringLiteral("windows"); -#elif defined(Q_OS_LINUX) +# elif defined(Q_OS_LINUX) ret << QStringLiteral("linux"); -#elif defined(Q_OS_OSX) - ret << QStringLiteral("osx"); -#elif defined(Q_OS_UNIX) - ret << QStringLiteral("generic_unix"); +# elif defined(Q_OS_MAC) + ret << QStringLiteral("mac"); +# else + struct utsname u; + if (uname(&u) != -1) + ret << QString::fromLatin1(u.sysname).toLower(); +# endif #endif return ret; } -- cgit v1.2.3 From a106be6f462b24bbb7caed5236d4f28e8a855c09 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Mon, 11 Nov 2013 09:15:24 +0100 Subject: Fix QCoreApplication documentation. Task-number: QTBUG-33360 Change-Id: Ifdc0bcc580d0a2dacc6a0bdce10aa278e0bdfe9c Reviewed-by: Jerome Pasion --- src/corelib/kernel/qcoreapplication.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 1ae4da12e8..43c64b7b2c 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -1027,7 +1027,7 @@ bool QCoreApplication::closingDown() You can call this function occasionally when your program is busy performing a long operation (e.g. copying a file). - In event you are running a local loop which calls this function + In the event that you are running a local loop which calls this function continuously, without an event loop, the \l{QEvent::DeferredDelete}{DeferredDelete} events will not be processed. This can affect the behaviour of widgets, -- cgit v1.2.3 From 4225e7103825a55ecddf27c21ec6a7ab5f5d0f63 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 11:40:26 +0100 Subject: QCollator: mark ctor explicit QCollator and QLocale are not equivalent types, so there should be no implicit conversion between them. Change-Id: I395f8dc3c35b4202c9276c3eea0686176f8e07cc Reviewed-by: Aleix Pol Gonzalez Reviewed-by: Thiago Macieira --- src/corelib/tools/qcollator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qcollator.h b/src/corelib/tools/qcollator.h index b99fd1c0cc..011c2a8d02 100644 --- a/src/corelib/tools/qcollator.h +++ b/src/corelib/tools/qcollator.h @@ -79,7 +79,7 @@ private: class Q_CORE_EXPORT QCollator { public: - QCollator(const QLocale &locale = QLocale()); + explicit QCollator(const QLocale &locale = QLocale()); QCollator(const QCollator &); ~QCollator(); QCollator &operator=(const QCollator &); -- cgit v1.2.3 From 2c450d90b6cb21fa5f4d2195d603c19c7bebb9ad Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 11:27:11 +0100 Subject: QCollator(SortKey): add member-swap This is required for a Qt value type these days. Change-Id: Ibd4e1581a4f4791a410caa10fede92c26b35dd9d Reviewed-by: Thiago Macieira --- src/corelib/tools/qcollator.cpp | 7 +++++++ src/corelib/tools/qcollator.h | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/tools/qcollator.cpp index a3a9ef940b..cfb5fe77ae 100644 --- a/src/corelib/tools/qcollator.cpp +++ b/src/corelib/tools/qcollator.cpp @@ -117,6 +117,13 @@ QCollator &QCollator::operator=(const QCollator &other) return *this; } +/*! + \fn void QCollator::swap(QCollator &other) + + Swaps this collator with \a other. This function is very fast and + never fails. +*/ + /*! \internal */ diff --git a/src/corelib/tools/qcollator.h b/src/corelib/tools/qcollator.h index 011c2a8d02..e5abc91967 100644 --- a/src/corelib/tools/qcollator.h +++ b/src/corelib/tools/qcollator.h @@ -61,8 +61,10 @@ public: QCollatorSortKey &operator=(const QCollatorSortKey &other); #ifdef Q_COMPILER_RVALUE_REFS inline QCollatorSortKey &operator=(QCollatorSortKey &&other) - { qSwap(d, other.d); return *this; } + { swap(other); return *this; } #endif + void swap(QCollatorSortKey &other) + { d.swap(other.d); } bool operator<(const QCollatorSortKey &key) const; int compare(const QCollatorSortKey &key) const; @@ -84,6 +86,9 @@ public: ~QCollator(); QCollator &operator=(const QCollator &); + void swap(QCollator &other) + { qSwap(d, other.d); } + void setLocale(const QLocale &locale); QLocale locale() const; -- cgit v1.2.3 From 8cbea7a886e336bca6e17f5cb8404a91cbec9fda Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 11:52:44 +0100 Subject: QFileSelector: mark ctor explicit This is standard for (QObject*) ctors. Change-Id: I4756ba50b1f3148d72e95e581d52a37ebd47a7ae Reviewed-by: John Layt Reviewed-by: Alan Alpert Reviewed-by: Olivier Goffart --- src/corelib/io/qfileselector.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qfileselector.h b/src/corelib/io/qfileselector.h index 9afd985757..cb5f71faae 100644 --- a/src/corelib/io/qfileselector.h +++ b/src/corelib/io/qfileselector.h @@ -52,7 +52,7 @@ class Q_CORE_EXPORT QFileSelector : public QObject { Q_OBJECT public: - QFileSelector(QObject *parent = 0); + explicit QFileSelector(QObject *parent = 0); ~QFileSelector(); QString select(const QString &filePath) const; -- cgit v1.2.3 From 3e803b5180e7059c01c15ea84cadd54982e1a221 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 11:37:37 +0100 Subject: QCollator: enable move semantics This necessitates adding d==0 checks in QCollator. By documenting that moved-from instances can only be assigned to or destroyed, we can limit the functions in which to check for d==0 to the assignment operator and the destructor. Doing otherwise would destroy all advantages of move semantics by introducing a heap allocation to re-populate other.d. Add a test for this (QCollator didn't have any before). Change-Id: Ic6ff202072822bebfd5e48259c3d0fa345a63118 Reviewed-by: Thiago Macieira --- src/corelib/tools/qcollator.cpp | 26 +++++++++++++++++++++++--- src/corelib/tools/qcollator.h | 6 ++++++ 2 files changed, 29 insertions(+), 3 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/tools/qcollator.cpp index cfb5fe77ae..80d330bfca 100644 --- a/src/corelib/tools/qcollator.cpp +++ b/src/corelib/tools/qcollator.cpp @@ -99,7 +99,7 @@ QCollator::QCollator(const QCollator &other) */ QCollator::~QCollator() { - if (!d->ref.deref()) + if (d && !d->ref.deref()) delete d; } @@ -109,14 +109,34 @@ QCollator::~QCollator() QCollator &QCollator::operator=(const QCollator &other) { if (this != &other) { - if (!d->ref.deref()) + if (d && !d->ref.deref()) delete d; d = other.d; - d->ref.ref(); + if (d) d->ref.ref(); } return *this; } +/* + \fn void QCollator::QCollator(QCollator &&other) + + Move constructor. Moves from \a other into this collator. + + Note that a moved-from QCollator can only be destroyed or assigned + to. The effect of calling other functions than the destructor or + one of the assignment operators is undefined. +*/ + +/* + \fn QCollator &QCollator::operator=(QCollator &&other) + + Move-assigns from \a other to this collator. + + Note that a moved-from QCollator can only be destroyed or assigned + to. The effect of calling other functions than the destructor or + one of the assignment operators is undefined. +*/ + /*! \fn void QCollator::swap(QCollator &other) diff --git a/src/corelib/tools/qcollator.h b/src/corelib/tools/qcollator.h index e5abc91967..1007aa7623 100644 --- a/src/corelib/tools/qcollator.h +++ b/src/corelib/tools/qcollator.h @@ -85,6 +85,12 @@ public: QCollator(const QCollator &); ~QCollator(); QCollator &operator=(const QCollator &); +#ifdef Q_COMPILER_RVALUE_REFS + QCollator(QCollator &&other) + : d(other.d) { other.d = 0; } + QCollator &operator=(QCollator &&other) + { swap(other); return *this; } +#endif void swap(QCollator &other) { qSwap(d, other.d); } -- cgit v1.2.3 From 70bc2e882ffc2ea998717d7fcde2b02a2124f52e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 11:29:47 +0100 Subject: QCollator(SortKey): declare as shared This enables specialisations of (std and q) swap using member-swap and declares the types movable for efficient use in Qt containers, and QList in particular. This is a binary-incompatible change, so cannot wait for 5.2.1. Change-Id: I7e90b6397ac4d00d0a7a5c42bae166c1b43e1994 Reviewed-by: Aleix Pol Gonzalez Reviewed-by: Thiago Macieira --- src/corelib/tools/qcollator.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qcollator.h b/src/corelib/tools/qcollator.h index 1007aa7623..941637e200 100644 --- a/src/corelib/tools/qcollator.h +++ b/src/corelib/tools/qcollator.h @@ -122,6 +122,9 @@ private: void detach(); }; +Q_DECLARE_SHARED(QCollatorSortKey) +Q_DECLARE_SHARED(QCollator) + QT_END_NAMESPACE #endif // QCOLLATOR_P_H -- cgit v1.2.3 From e721cf15081c8174a38797cc88f7c5197d9e527c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 13 Nov 2013 11:25:19 +0100 Subject: QCollatorSortKey: inline operator< This code was duplicated in every qcollator_platform.cpp and identical everywhere, except in _icu, which uses a QByteArray m_key and the implementation used QByteArray::operator<, which is semantically and probably code-wise identical to what the other implementations did (after inlining). Inlining this function removes a potential maintenance problem and increases speed without violating encapsulation. Change-Id: If3e9d38a7d4326b49f0611a9f4187c53960e8a03 Reviewed-by: Lars Knoll --- src/corelib/tools/qcollator.cpp | 9 +++++---- src/corelib/tools/qcollator.h | 6 +++++- src/corelib/tools/qcollator_icu.cpp | 5 ----- src/corelib/tools/qcollator_macx.cpp | 5 ----- src/corelib/tools/qcollator_posix.cpp | 5 ----- src/corelib/tools/qcollator_win.cpp | 5 ----- 6 files changed, 10 insertions(+), 25 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/tools/qcollator.cpp index 80d330bfca..9c97d6b158 100644 --- a/src/corelib/tools/qcollator.cpp +++ b/src/corelib/tools/qcollator.cpp @@ -328,12 +328,13 @@ QCollatorSortKey& QCollatorSortKey::operator=(const QCollatorSortKey &other) } /*! - \fn bool QCollatorSortKey::operator<(const QCollatorSortKey &otherKey) const + \fn bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs) + \relates QCollatorSortKey - According to the QCollator that created the key, returns \c true if the - key should be sorted before than \a otherKey; otherwise returns \c false. + According to the QCollator that created the keys, returns \c true if \a lhs + should be sorted before \a rhs; otherwise returns \c false. - \sa compare() + \sa QCollatorSortKey::compare() */ /*! diff --git a/src/corelib/tools/qcollator.h b/src/corelib/tools/qcollator.h index 941637e200..781e95b10c 100644 --- a/src/corelib/tools/qcollator.h +++ b/src/corelib/tools/qcollator.h @@ -66,7 +66,6 @@ public: void swap(QCollatorSortKey &other) { d.swap(other.d); } - bool operator<(const QCollatorSortKey &key) const; int compare(const QCollatorSortKey &key) const; protected: @@ -78,6 +77,11 @@ private: QCollatorSortKey(); }; +inline bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs) +{ + return lhs.compare(rhs) < 0; +} + class Q_CORE_EXPORT QCollator { public: diff --git a/src/corelib/tools/qcollator_icu.cpp b/src/corelib/tools/qcollator_icu.cpp index 46f830a34c..407a493d25 100644 --- a/src/corelib/tools/qcollator_icu.cpp +++ b/src/corelib/tools/qcollator_icu.cpp @@ -151,11 +151,6 @@ QCollatorSortKey QCollator::sortKey(const QString &string) const return QCollatorSortKey(new QCollatorSortKeyPrivate(result)); } -bool QCollatorSortKey::operator<(const QCollatorSortKey &otherKey) const -{ - return d->m_key < otherKey.d->m_key; -} - int QCollatorSortKey::compare(const QCollatorSortKey &otherKey) const { return qstrcmp(d->m_key, otherKey.d->m_key); diff --git a/src/corelib/tools/qcollator_macx.cpp b/src/corelib/tools/qcollator_macx.cpp index 8edd190fbe..8985cd4eba 100644 --- a/src/corelib/tools/qcollator_macx.cpp +++ b/src/corelib/tools/qcollator_macx.cpp @@ -162,11 +162,6 @@ QCollatorSortKey QCollator::sortKey(const QString &string) const return QCollatorSortKey(new QCollatorSortKeyPrivate(ret)); } -bool QCollatorSortKey::operator<(const QCollatorSortKey &key) const -{ - return compare(key) < 0; -} - int QCollatorSortKey::compare(const QCollatorSortKey &key) const { SInt32 order; diff --git a/src/corelib/tools/qcollator_posix.cpp b/src/corelib/tools/qcollator_posix.cpp index a43618dcf1..b47b546d01 100644 --- a/src/corelib/tools/qcollator_posix.cpp +++ b/src/corelib/tools/qcollator_posix.cpp @@ -135,11 +135,6 @@ QCollatorSortKey QCollator::sortKey(const QString &string) const return QCollatorSortKey(new QCollatorSortKeyPrivate(result)); } -bool QCollatorSortKey::operator<(const QCollatorSortKey &otherKey) const -{ - return compare(otherKey) < 0; -} - int QCollatorSortKey::compare(const QCollatorSortKey &otherKey) const { return std::wcscmp(d->m_key.constData(), diff --git a/src/corelib/tools/qcollator_win.cpp b/src/corelib/tools/qcollator_win.cpp index 282711fbc6..8e59000946 100644 --- a/src/corelib/tools/qcollator_win.cpp +++ b/src/corelib/tools/qcollator_win.cpp @@ -155,11 +155,6 @@ QCollatorSortKey QCollator::sortKey(const QString &string) const return QCollatorSortKey(new QCollatorSortKeyPrivate(ret)); } -bool QCollatorSortKey::operator<(const QCollatorSortKey &otherKey) const -{ - return d->m_key < otherKey.d->m_key; -} - int QCollatorSortKey::compare(const QCollatorSortKey &otherKey) const { return d->m_key.compare(otherKey.d->m_key); -- cgit v1.2.3