From f5021835dfb4b0bf974794b598cbdf9f0f95898d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 6 Dec 2023 09:05:03 -0800 Subject: qTo*ViewIgnoringNull: further ignore nulls Commit ba5db13c8d197706ac3dec5d351b6684f809f2e4 ("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 --- src/corelib/text/qutf8stringview.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/corelib/text/qutf8stringview.h') diff --git a/src/corelib/text/qutf8stringview.h b/src/corelib/text/qutf8stringview.h index d653b99cfb..bd83da8946 100644 --- a/src/corelib/text/qutf8stringview.h +++ b/src/corelib/text/qutf8stringview.h @@ -347,7 +347,7 @@ Q_DECLARE_TYPEINFO_BODY(QBasicUtf8StringView, Q_PRIMITIVE_TYPE); template , 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 -- cgit v1.2.3