QtPrivate::equalStrings(): enforce matching size where applicable
Commitbb108a7b74f6e7added these functions and already placed the checking for the size in the inline code. Aside from the operators==, the only other place that calls equalStrings() directly is QAnyStringView::equal() and that also checks the size for the non-UTF-8 string views do match. Unfortunately, the size checking for UTF-8 was only added in52e0a91fbc. This reverts commite0eb93d9a2("QLatin1StringView: delegate operator== to QByteArrayView") because that would compare the sizes again. Change-Id: I83dda2d36c904517b3c0fffd17b38e422b5e2c25 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
parent
a6a5681470
commit
1560e0161a
|
|
@ -1348,10 +1348,8 @@ static int ucstrncmp(const char16_t *a, const char *b, size_t l)
|
|||
|
||||
// Unicode case-sensitive equality
|
||||
template <typename Char2>
|
||||
static bool ucstreq(const char16_t *a, size_t alen, const Char2 *b, size_t blen)
|
||||
static bool ucstreq(const char16_t *a, size_t alen, const Char2 *b)
|
||||
{
|
||||
if (alen != blen)
|
||||
return false;
|
||||
if constexpr (std::is_same_v<decltype(a), decltype(b)>) {
|
||||
if (a == b)
|
||||
return true;
|
||||
|
|
@ -1394,12 +1392,14 @@ static int latin1nicmp(const char *lhsChar, qsizetype lSize, const char *rhsChar
|
|||
|
||||
bool QtPrivate::equalStrings(QStringView lhs, QStringView rhs) noexcept
|
||||
{
|
||||
return ucstreq(lhs.utf16(), lhs.size(), rhs.utf16(), rhs.size());
|
||||
Q_ASSERT(lhs.size() == rhs.size());
|
||||
return ucstreq(lhs.utf16(), lhs.size(), rhs.utf16());
|
||||
}
|
||||
|
||||
bool QtPrivate::equalStrings(QStringView lhs, QLatin1StringView rhs) noexcept
|
||||
{
|
||||
return ucstreq(lhs.utf16(), lhs.size(), rhs.latin1(), rhs.size());
|
||||
Q_ASSERT(lhs.size() == rhs.size());
|
||||
return ucstreq(lhs.utf16(), lhs.size(), rhs.latin1());
|
||||
}
|
||||
|
||||
bool QtPrivate::equalStrings(QLatin1StringView lhs, QStringView rhs) noexcept
|
||||
|
|
@ -1409,7 +1409,8 @@ bool QtPrivate::equalStrings(QLatin1StringView lhs, QStringView rhs) noexcept
|
|||
|
||||
bool QtPrivate::equalStrings(QLatin1StringView lhs, QLatin1StringView rhs) noexcept
|
||||
{
|
||||
return QByteArrayView(lhs) == QByteArrayView(rhs);
|
||||
Q_ASSERT(lhs.size() == rhs.size());
|
||||
return (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
|
||||
}
|
||||
|
||||
bool QtPrivate::equalStrings(QBasicUtf8StringView<false> lhs, QStringView rhs) noexcept
|
||||
|
|
@ -1434,7 +1435,14 @@ bool QtPrivate::equalStrings(QBasicUtf8StringView<false> lhs, QLatin1StringView
|
|||
|
||||
bool QtPrivate::equalStrings(QBasicUtf8StringView<false> lhs, QBasicUtf8StringView<false> rhs) noexcept
|
||||
{
|
||||
return lhs.size() == rhs.size() && (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) || defined(QT_STATIC)
|
||||
Q_ASSERT(lhs.size() == rhs.size());
|
||||
#else
|
||||
// operator== didn't enforce size prior to Qt 6.2
|
||||
if (lhs.size() != rhs.size())
|
||||
return false;
|
||||
#endif
|
||||
return (!lhs.size() || memcmp(lhs.data(), rhs.data(), lhs.size()) == 0);
|
||||
}
|
||||
|
||||
bool QAnyStringView::equal(QAnyStringView lhs, QAnyStringView rhs) noexcept
|
||||
|
|
|
|||
Loading…
Reference in New Issue