qTo*ViewIgnoringNull: further ignore nulls
Commit ba5db13c8d ("QStringView: add
internal qToStringViewIgnoringNull()") said:
As long as a null QString still returns non-null data(), QStringView's
QString constructor needs to call isNull(). That's a branch we often
can do without, so add an internal function that bypasses this
correctness check.
It's internal, since we might have a Q6String that returns nullptr
data() when null, which will remove the need for this function.
For Qt 6, we made QString and QByteArray be able to return nullptr from
data() when null... but that's not enabled by default yet. However, the
begin() functions do return nullptr, so we can avoid the extra branch
the commit was talking about.
Task-number: QTBUG-119750
Change-Id: Ica7a43f6147b49c187ccfffd179e4cf032bc8565
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
bb10
parent
a116b2ddfc
commit
f5021835df
|
|
@ -352,7 +352,7 @@ template <typename QStringLike, std::enable_if_t<std::disjunction_v<
|
|||
std::is_same<QStringLike, QByteArray>
|
||||
>, bool> = true>
|
||||
[[nodiscard]] inline QAnyStringView qToAnyStringViewIgnoringNull(const QStringLike &s) noexcept
|
||||
{ return QAnyStringView(s.data(), s.size()); }
|
||||
{ return QAnyStringView(s.begin(), s.size()); }
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE);
|
|||
template<typename QByteArrayLike,
|
||||
std::enable_if_t<std::is_same_v<QByteArrayLike, QByteArray>, bool> = true>
|
||||
[[nodiscard]] inline QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept
|
||||
{ return QByteArrayView(b.data(), b.size()); }
|
||||
{ return QByteArrayView(b.begin(), b.size()); }
|
||||
|
||||
inline int QByteArrayView::compare(QByteArrayView a, Qt::CaseSensitivity cs) const noexcept
|
||||
{
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ template <typename QStringLike, typename std::enable_if<
|
|||
std::is_same<QStringLike, QString>::value,
|
||||
bool>::type = true>
|
||||
inline QStringView qToStringViewIgnoringNull(const QStringLike &s) noexcept
|
||||
{ return QStringView(s.data(), s.size()); }
|
||||
{ return QStringView(s.begin(), s.size()); }
|
||||
|
||||
// QChar inline functions:
|
||||
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ Q_DECLARE_TYPEINFO_BODY(QBasicUtf8StringView<UseChar8T>, Q_PRIMITIVE_TYPE);
|
|||
|
||||
template <typename QStringLike, std::enable_if_t<std::is_same_v<QStringLike, QByteArray>, bool> = true>
|
||||
[[nodiscard]] inline q_no_char8_t::QUtf8StringView qToUtf8StringViewIgnoringNull(const QStringLike &s) noexcept
|
||||
{ return q_no_char8_t::QUtf8StringView(s.data(), s.size()); }
|
||||
{ return q_no_char8_t::QUtf8StringView(s.begin(), s.size()); }
|
||||
#endif // Q_QDOC
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -433,7 +433,7 @@ void tst_QByteArrayView::fromQByteArray() const
|
|||
QByteArray empty = "";
|
||||
|
||||
QVERIFY(QByteArrayView(null).isNull());
|
||||
QVERIFY(!qToByteArrayViewIgnoringNull(null).isNull());
|
||||
QVERIFY(qToByteArrayViewIgnoringNull(null).isNull());
|
||||
|
||||
QVERIFY(QByteArrayView(null).isEmpty());
|
||||
QVERIFY(qToByteArrayViewIgnoringNull(null).isEmpty());
|
||||
|
|
|
|||
Loading…
Reference in New Issue