diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2020-01-16 16:25:06 +0100 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2020-01-16 16:25:06 +0100 |
commit | 1d333d3375874efb8d37df37dc5ef561573794ad (patch) | |
tree | 2d8c995f64c05c84c1fcceb2c5cb40fcae69855f /src/qml/jsruntime/qv4string_p.h | |
parent | b106d86c433706928b0b0c206a0d9f831681e1bf (diff) | |
parent | e79a2658cde899d6ee11ec3c0d0a3768eb2c864b (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Change-Id: I0c5b939c70bdb91ccdf7068784308416dcaa5736
Diffstat (limited to 'src/qml/jsruntime/qv4string_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4string_p.h | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h index 52fe09cd72..d5d11ef660 100644 --- a/src/qml/jsruntime/qv4string_p.h +++ b/src/qml/jsruntime/qv4string_p.h @@ -77,7 +77,18 @@ struct Q_QML_PRIVATE_EXPORT StringOrSymbol : Base StringType_Complex = StringType_AddedString }; - mutable QStringData *text; + void init() { + Base::init(); + new (&textStorage) QStringPrivate; + } + + void init(QStringPrivate text) + { + Base::init(); + new (&textStorage) QStringPrivate(std::move(text)); + } + + mutable std::aligned_storage<sizeof(QStringPrivate), alignof(QStringPrivate)>::type textStorage; mutable PropertyKey identifier; mutable uint subtype; mutable uint stringHash; @@ -85,12 +96,11 @@ struct Q_QML_PRIVATE_EXPORT StringOrSymbol : Base static void markObjects(Heap::Base *that, MarkStack *markStack); void destroy(); + QStringPrivate &text() const { return *reinterpret_cast<QStringPrivate *>(&textStorage); } + inline QString toQString() const { - if (!text) - return QString(); - QStringDataPtr ptr = { text }; - text->ref.ref(); - return QString(ptr); + QStringPrivate dd = text(); + return QString(std::move(dd)); } void createHashValue() const; inline unsigned hashValue() const { @@ -113,14 +123,12 @@ struct Q_QML_PRIVATE_EXPORT String : StringOrSymbol { void simplifyString() const; int length() const; std::size_t retainedTextSize() const { - return subtype >= StringType_Complex ? 0 : (std::size_t(text->size) * sizeof(QChar)); + return subtype >= StringType_Complex ? 0 : (std::size_t(text().size) * sizeof(QChar)); } inline QString toQString() const { if (subtype >= StringType_Complex) simplifyString(); - QStringDataPtr ptr = { text }; - text->ref.ref(); - return QString(ptr); + return StringOrSymbol::toQString(); } inline bool isEqualTo(const String *other) const { if (this == other) @@ -158,7 +166,7 @@ Q_STATIC_ASSERT(std::is_trivial< ComplexString >::value); inline int String::length() const { - return text ? text->size : static_cast<const ComplexString *>(this)->len; + return subtype < StringType_AddedString ? text().size : static_cast<const ComplexString *>(this)->len; } } @@ -252,7 +260,7 @@ public: } if (subtype) - *subtype = (charToUInt(ch) == '@') ? Heap::StringOrSymbol::StringType_Symbol : Heap::StringOrSymbol::StringType_Regular; + *subtype = (ch != end && charToUInt(ch) == '@') ? Heap::StringOrSymbol::StringType_Symbol : Heap::StringOrSymbol::StringType_Regular; return h; } }; |