From 497275a8ba12b251869c0112984d8c3cbe00fdfc Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 4 Dec 2022 12:36:50 -0800 Subject: Q{Latin1,}StringView: invert members so the order is (data,size) in Qt7 Matches Q{Any,Utf8}StringView as well as std::basic_string_view in Microsoft's STL and LLVM libc++, but not GCC's libstdc++. Interestingly, it does match the order in libstdc++'s non-small std::basic_string. Applied for bootstrapped use, so we ensure this works and keeps working. Change-Id: I51d12ccdc56c4ad2af07fffd172db18254fff083 Reviewed-by: Marc Mutz --- src/corelib/text/qstringview.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/corelib/text/qstringview.h') diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 95b089d565..fa2ad80a46 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -137,15 +137,20 @@ private: { return str; } public: - constexpr QStringView() noexcept - : m_size(0), m_data(nullptr) {} + constexpr QStringView() noexcept {} constexpr QStringView(std::nullptr_t) noexcept : QStringView() {} template = true> constexpr QStringView(const Char *str, qsizetype len) +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) + : m_data(castHelper(str)), + m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len)) +#else : m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len)), - m_data(castHelper(str)) {} + m_data(castHelper(str)) +#endif + {} template = true> constexpr QStringView(const Char *f, const Char *l) @@ -426,8 +431,13 @@ public: [[nodiscard]] constexpr QChar first() const { return front(); } [[nodiscard]] constexpr QChar last() const { return back(); } private: - qsizetype m_size; - const storage_type *m_data; +#if QT_VERSION >= QT_VERSION_CHECK(7, 0, 0) || defined(QT_BOOTSTRAPPED) + const storage_type *m_data = nullptr; + qsizetype m_size = 0; +#else + qsizetype m_size = 0; + const storage_type *m_data = nullptr; +#endif constexpr int compare_single_char_helper(int diff) const noexcept { return diff ? diff : size() > 1 ? 1 : 0; } -- cgit v1.2.3