summaryrefslogtreecommitdiffstats
path: root/src/corelib/text/qutf8stringview.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-12-06 09:05:03 -0800
committerThiago Macieira <thiago.macieira@intel.com>2023-12-21 11:13:32 -0800
commitf5021835dfb4b0bf974794b598cbdf9f0f95898d (patch)
tree2c641f8406d9a4c03f61909ee929cb00affea7e7 /src/corelib/text/qutf8stringview.h
parenta116b2ddfc9e91736b1ec4edda6500e9c8f5f301 (diff)
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 <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/text/qutf8stringview.h')
-rw-r--r--src/corelib/text/qutf8stringview.h2
1 files changed, 1 insertions, 1 deletions
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<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