summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-04-06 21:07:02 +0200
committerMarc Mutz <marc.mutz@kdab.com>2017-04-07 08:32:39 +0000
commit95db1f6caef29553ca7c9cf33c8009b9cc95e302 (patch)
tree61634925da45005fccd38f2208a5f0b66a25188f
parent95263dbf7a7fe6ae72abc59b7a576ab66b886238 (diff)
Optimize comparisons of QChar with QLatin1String, QString, and QStringRef
Instead of blindly calling the general compare function with a 1-char string, compare size() and front() to 1 and the QChar, respectively. Change-Id: I6c83c0772d16294ce6dd7eb058513d717208d6cd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/corelib/tools/qstring.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 87e88d74bd..696aeb2efb 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -1657,7 +1657,7 @@ inline bool operator>=(const QStringRef &lhs, QLatin1String rhs) Q_DECL_NOTHROW
// QChar <> QString
inline bool operator==(QChar lhs, const QString &rhs) Q_DECL_NOTHROW
-{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) == 0; }
+{ return rhs.size() == 1 && lhs == rhs.front(); }
inline bool operator< (QChar lhs, const QString &rhs) Q_DECL_NOTHROW
{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; }
inline bool operator> (QChar lhs, const QString &rhs) Q_DECL_NOTHROW
@@ -1676,7 +1676,7 @@ inline bool operator>=(const QString &lhs, QChar rhs) Q_DECL_NOTHROW { return !(
// QChar <> QStringRef
inline bool operator==(QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW
-{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) == 0; }
+{ return rhs.size() == 1 && lhs == rhs.front(); }
inline bool operator< (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW
{ return QString::compare_helper(&lhs, 1, rhs.data(), rhs.size()) < 0; }
inline bool operator> (QChar lhs, const QStringRef &rhs) Q_DECL_NOTHROW
@@ -1695,7 +1695,7 @@ inline bool operator>=(const QStringRef &lhs, QChar rhs) Q_DECL_NOTHROW { return
// QChar <> QLatin1String
inline bool operator==(QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW
-{ return QString::compare_helper(&lhs, 1, rhs) == 0; }
+{ return rhs.size() == 1 && lhs == rhs.front(); }
inline bool operator< (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW
{ return QString::compare_helper(&lhs, 1, rhs) < 0; }
inline bool operator> (QChar lhs, QLatin1String rhs) Q_DECL_NOTHROW