QLatin1StringView: delegate operator== to QByteArrayView

It's the same implementation. This also inlines the actual comparison,
to allow the compiler to implement the inline memcmp, if it so wishes.

operator< could be changed too, but QByteArrayView's makes an out-of-
line call to QtPrivate::compareMemory, whereas QLatin1StringView's calls
memcmp() directly, which allows the compiler to optimize.

Change-Id: I89c4eb48af38408daa7cfffd16fde9f2b0a8590b
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Thiago Macieira 2022-07-01 21:51:06 -07:00
parent 751919d4de
commit e0eb93d9a2
3 changed files with 3 additions and 3 deletions

View File

@ -300,7 +300,7 @@ public:
[[nodiscard]] constexpr char last() const { return back(); }
friend inline bool operator==(QByteArrayView lhs, QByteArrayView rhs) noexcept
{ return lhs.size() == rhs.size() && QtPrivate::compareMemory(lhs, rhs) == 0; }
{ return lhs.size() == rhs.size() && (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0); }
friend inline bool operator!=(QByteArrayView lhs, QByteArrayView rhs) noexcept
{ return !(lhs == rhs); }
friend inline bool operator< (QByteArrayView lhs, QByteArrayView rhs) noexcept

View File

@ -1402,7 +1402,7 @@ bool QtPrivate::equalStrings(QLatin1StringView lhs, QStringView rhs) noexcept
bool QtPrivate::equalStrings(QLatin1StringView lhs, QLatin1StringView rhs) noexcept
{
return lhs.size() == rhs.size() && (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
return QByteArrayView(lhs) == QByteArrayView(rhs);
}
bool QtPrivate::equalStrings(QBasicUtf8StringView<false> lhs, QStringView rhs) noexcept

View File

@ -270,7 +270,7 @@ public:
{ return qTokenize(*this, std::forward<Needle>(needle), flags...); }
friend inline bool operator==(QLatin1StringView s1, QLatin1StringView s2) noexcept
{ return s1.size() == s2.size() && (!s1.size() || !memcmp(s1.latin1(), s2.latin1(), s1.size())); }
{ return QByteArrayView(s1) == QByteArrayView(s2); }
friend inline bool operator!=(QLatin1StringView s1, QLatin1StringView s2) noexcept
{ return !(s1 == s2); }
friend inline bool operator<(QLatin1StringView s1, QLatin1StringView s2) noexcept