diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-12-04 12:36:50 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-12-06 22:24:14 -0800 |
commit | 497275a8ba12b251869c0112984d8c3cbe00fdfc (patch) | |
tree | 3d7fdc89bf44b97440027f7db7ef71de3fbec263 /src/corelib/text/qstringview.h | |
parent | 1501f45c335f0a82843e3133ec2ef54d93546cf9 (diff) |
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 <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/text/qstringview.h')
-rw-r--r-- | src/corelib/text/qstringview.h | 20 |
1 files changed, 15 insertions, 5 deletions
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 <typename Char, if_compatible_char<Char> = 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 <typename Char, if_compatible_char<Char> = 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; } |