summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qstringview.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/text/qstringview.h')
-rw-r--r--src/corelib/text/qstringview.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h
index a2e55f5b16..9b85dcffa5 100644
--- a/src/corelib/text/qstringview.h
+++ b/src/corelib/text/qstringview.h
@@ -259,7 +259,7 @@ public:
{ return QtPrivate::compareStrings(*this, other, cs); }
Q_REQUIRED_RESULT inline int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept;
Q_REQUIRED_RESULT Q_DECL_CONSTEXPR int compare(QChar c) const noexcept
- { return empty() || front() == c ? size() - 1 : *utf16() - c.unicode() ; }
+ { return size() >= 1 ? compare_single_char_helper(*utf16() - c.unicode()) : -1; }
Q_REQUIRED_RESULT int compare(QChar c, Qt::CaseSensitivity cs) const noexcept
{ return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); }
@@ -332,6 +332,9 @@ public:
private:
qsizetype m_size;
const storage_type *m_data;
+
+ Q_DECL_CONSTEXPR int compare_single_char_helper(int diff) const noexcept
+ { return diff ? diff : size() > 1 ? 1 : 0; }
};
Q_DECLARE_TYPEINFO(QStringView, Q_PRIMITIVE_TYPE);