From 7d18ad49a37440835bb38bd77bc4e0991387ada0 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 4 Oct 2023 13:24:31 +0200 Subject: [PATCH] QStringView: simplify the constructor from QString We have to single QString out because of the isNull/isEmpty distinction. Still, we can avoid having a constructor template on it constrained on the argument being precisely QString. This is a historic remnant; in Qt 5 the constructor also worked with QStringRef. Change-Id: I5457a83d5b77887f57ea9910a826f729ec276d28 Reviewed-by: Thiago Macieira --- src/corelib/text/qstring.h | 7 +++++++ src/corelib/text/qstringview.h | 11 +---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 06c6f668c4..31d19f7fe6 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -1436,6 +1436,13 @@ inline QString &&asString(QString &&s) { return std::move(s); } static_cast(static_cast(QtPrivate::asString(string).utf16())) #endif +// +// QStringView::QStringView(const QString &) implementation +// + +inline QStringView::QStringView(const QString &str) noexcept + : QStringView(str.isNull() ? nullptr : str.data(), qsizetype(str.size())) {} + // // QStringView::arg() implementation // diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 05e5ec3fdb..d62dd71bdf 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -96,9 +96,6 @@ private: template using if_compatible_pointer = typename std::enable_if::value, bool>::type; - template - using if_compatible_qstring_like = typename std::enable_if::value, bool>::type; - template using if_compatible_container = typename std::enable_if::value, bool>::type; @@ -155,13 +152,7 @@ public: : QStringView(str, str ? lengthHelperPointer(str) : 0) {} #endif -#ifdef Q_QDOC - QStringView(const QString &str) noexcept; -#else - template = true> - QStringView(const String &str) noexcept - : QStringView(str.isNull() ? nullptr : str.data(), qsizetype(str.size())) {} -#endif + inline QStringView(const QString &str) noexcept; template = true> constexpr Q_ALWAYS_INLINE QStringView(const Container &c) noexcept