From ba5db13c8d197706ac3dec5d351b6684f809f2e4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 12 Apr 2017 09:52:24 +0200 Subject: QStringView: add internal qToStringViewIgnoringNull() 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. What the QStringView(QString) ctor does will also have to be re-evaluated come Qt 6, but for now, keep the public QString- QStringView conversion correct. Change-Id: I35dc7383bc3bd018f46aeec429185135a38ddcef Reviewed-by: Lars Knoll Reviewed-by: Edward Welbourne --- src/corelib/tools/qstringview.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/corelib/tools/qstringview.h') diff --git a/src/corelib/tools/qstringview.h b/src/corelib/tools/qstringview.h index 7aef056dee..54d054baaa 100644 --- a/src/corelib/tools/qstringview.h +++ b/src/corelib/tools/qstringview.h @@ -272,6 +272,12 @@ private: }; Q_DECLARE_TYPEINFO(QStringView, Q_MOVABLE_TYPE); +template ::value || std::is_same::value, + bool>::type = true> +inline QStringView qToStringViewIgnoringNull(const QStringLike &s) Q_DECL_NOTHROW +{ return QStringView(s.data(), s.size()); } + QT_END_NAMESPACE #endif /* QSTRINGVIEW_H */ -- cgit v1.2.3