diff options
Diffstat (limited to 'src/corelib/text/qstringliteral.h')
-rw-r--r-- | src/corelib/text/qstringliteral.h | 44 |
1 files changed, 13 insertions, 31 deletions
diff --git a/src/corelib/text/qstringliteral.h b/src/corelib/text/qstringliteral.h index a0d4ddc30b..a8cf8e2c64 100644 --- a/src/corelib/text/qstringliteral.h +++ b/src/corelib/text/qstringliteral.h @@ -49,8 +49,6 @@ QT_BEGIN_NAMESPACE -typedef QTypedArrayData<ushort> QStringData; - // all our supported compilers support Unicode string literals, // even if their Q_COMPILER_UNICODE_STRING has been revoked due // to lacking stdlib support. But QStringLiteral only needs the @@ -65,43 +63,27 @@ Q_STATIC_ASSERT_X(sizeof(qunicodechar) == 2, #define QStringLiteral(str) \ ([]() noexcept -> QString { \ enum { Size = sizeof(QT_UNICODE_LITERAL(str))/2 - 1 }; \ - static const QStaticStringData<Size> qstring_literal = { \ - Q_STATIC_STRING_DATA_HEADER_INITIALIZER(Size), \ - QT_UNICODE_LITERAL(str) }; \ - QStringDataPtr holder = { qstring_literal.data_ptr() }; \ - const QString qstring_literal_temp(holder); \ - return qstring_literal_temp; \ + static const QArrayData qstring_literal = { \ + Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, Size, 0, sizeof(QArrayData) \ + }; \ + QStringPrivate holder = { \ + const_cast<QArrayData *>(&qstring_literal), \ + reinterpret_cast<ushort *>(const_cast<qunicodechar *>(QT_UNICODE_LITERAL(str))), \ + Size \ + }; \ + return QString(holder); \ }()) \ /**/ -#define Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, offset) \ - { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, size, 0, offset } \ - /**/ - -#define Q_STATIC_STRING_DATA_HEADER_INITIALIZER(size) \ - Q_STATIC_STRING_DATA_HEADER_INITIALIZER_WITH_OFFSET(size, sizeof(QStringData)) \ - /**/ - #if QT_DEPRECATED_SINCE(5, 14) # define QStringViewLiteral(str) QStringView(QT_UNICODE_LITERAL(str), QtPrivate::Deprecated) #endif -template <int N> -struct QStaticStringData -{ - QArrayData str; - qunicodechar data[N + 1]; - - QStringData *data_ptr() const - { - Q_ASSERT(str.isStatic()); - return const_cast<QStringData *>(static_cast<const QStringData*>(&str)); - } -}; - -struct QStringDataPtr +struct QStringPrivate { - QStringData *ptr; + QArrayData *d; + ushort *b; + uint size; }; QT_END_NAMESPACE |