From 95db1f6caef29553ca7c9cf33c8009b9cc95e302 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 6 Apr 2017 21:07:02 +0200 Subject: [PATCH] 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 Reviewed-by: Lars Knoll --- src/corelib/tools/qstring.h | 6 +++--- 1 file 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