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>
This commit is contained in:
parent
95263dbf7a
commit
95db1f6cae
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user