QtPrivate::equalStrings(): enforce matching size where applicable
Commit 8a7b74f6e71d6b8264f365148bf5a04db4038617 added 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 in 52e0a91fbc187ca09d3ea6279e8bdce982edc586. This reverts commit e0eb93d9a2b104ac8d7596c419d1f13dc9db9b1b ("QLatin1StringView: delegate operator== to QByteArrayView") because that would compare the sizes again. Change-Id: I83dda2d36c904517b3c0fffd17b38e422b5e2c25 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
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…
x
Reference in New Issue
Block a user