summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2013-11-13 11:25:19 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-17 09:47:34 +0100
commite721cf15081c8174a38797cc88f7c5197d9e527c (patch)
treea50c471ab1867940869fe59912b97b6ea3a4e6af
parent70bc2e882ffc2ea998717d7fcde2b02a2124f52e (diff)
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 <lars.knoll@digia.com>
-rw-r--r--src/corelib/tools/qcollator.cpp9
-rw-r--r--src/corelib/tools/qcollator.h6
-rw-r--r--src/corelib/tools/qcollator_icu.cpp5
-rw-r--r--src/corelib/tools/qcollator_macx.cpp5
-rw-r--r--src/corelib/tools/qcollator_posix.cpp5
-rw-r--r--src/corelib/tools/qcollator_win.cpp5
6 files changed, 10 insertions, 25 deletions
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);