diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-04-29 11:32:19 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2014-07-22 13:49:05 +0200 |
commit | 541da479754e6da07463cd6f0dd0e24bc6746494 (patch) | |
tree | e4d949f1e1d8a71f8f868e02d01e0742fb8b55c2 /src/qml/jsruntime/qv4string_p.h | |
parent | 233b339c480e313bc49d16f9b85bc4318f4c3f48 (diff) |
Convert String to the new storage layout
Change-Id: Ifa9aac63fdb270fb449f11832a1792caeb6c6724
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4string_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4string_p.h | 86 |
1 files changed, 47 insertions, 39 deletions
diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h index 615be29496..9a74136f6a 100644 --- a/src/qml/jsruntime/qv4string_p.h +++ b/src/qml/jsruntime/qv4string_p.h @@ -53,8 +53,34 @@ struct Identifier; struct Q_QML_PRIVATE_EXPORT String : public Managed { #ifndef V4_BOOTSTRAP + struct Data : Managed::Data { + union { + mutable QStringData *text; + mutable String *left; + }; + union { + mutable Identifier *identifier; + mutable String *right; + }; + mutable uint stringHash; + mutable uint largestSubLength; + uint len; + }; + struct { + union { + mutable QStringData *text; + mutable String *left; + }; + union { + mutable Identifier *identifier; + mutable String *right; + }; + mutable uint stringHash; + mutable uint largestSubLength; + uint len; + } __data; // ### FIXME: Should this be a V4_OBJECT - V4_OBJECT + V4_OBJECT_NEW Q_MANAGED_TYPE(String) enum { IsString = true @@ -70,8 +96,8 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { String(ExecutionEngine *engine, const QString &text); String(ExecutionEngine *engine, String *l, String *n); ~String() { - if (!stringData()->largestSubLength && !stringData()->text->ref.deref()) - QStringData::deallocate(stringData()->text); + if (!d()->largestSubLength && !d()->text->ref.deref()) + QStringData::deallocate(d()->text); } bool equals(const StringRef other) const; @@ -80,8 +106,8 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { return true; if (hashValue() != other->hashValue()) return false; - Q_ASSERT(!stringData()->largestSubLength); - if (stringData()->identifier && stringData()->identifier == other->stringData()->identifier) + Q_ASSERT(!d()->largestSubLength); + if (d()->identifier && d()->identifier == other->d()->identifier) return true; if (subtype() >= StringType_UInt && subtype() == other->subtype()) return true; @@ -94,10 +120,10 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { } inline QString toQString() const { - if (stringData()->largestSubLength) + if (d()->largestSubLength) simplifyString(); - QStringDataPtr ptr = { stringData()->text }; - stringData()->text->ref.ref(); + QStringDataPtr ptr = { d()->text }; + d()->text->ref.ref(); return QString(ptr); } @@ -106,22 +132,22 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { inline unsigned hashValue() const { if (subtype() == StringType_Unknown) createHashValue(); - Q_ASSERT(!stringData()->largestSubLength); + Q_ASSERT(!d()->largestSubLength); - return stringData()->stringHash; + return d()->stringHash; } uint asArrayIndex() const { if (subtype() == StringType_Unknown) createHashValue(); - Q_ASSERT(!stringData()->largestSubLength); + Q_ASSERT(!d()->largestSubLength); if (subtype() == StringType_ArrayIndex) - return stringData()->stringHash; + return d()->stringHash; return UINT_MAX; } uint toUInt(bool *ok) const; void makeIdentifier() const { - if (stringData()->identifier) + if (d()->identifier) return; makeIdentifierImpl(); } @@ -134,36 +160,18 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { bool startsWithUpper() const { const String *l = this; - while (l->stringData()->largestSubLength) - l = l->stringData()->left; - return l->stringData()->text->size && QChar::isUpper(l->stringData()->text->data()[0]); + while (l->d()->largestSubLength) + l = l->d()->left; + return l->d()->text->size && QChar::isUpper(l->d()->text->data()[0]); } int length() const { - Q_ASSERT((stringData()->largestSubLength && - (stringData()->len == stringData()->left->stringData()->len + stringData()->right->stringData()->len)) || - stringData()->len == (uint)stringData()->text->size); - return stringData()->len; + Q_ASSERT((d()->largestSubLength && + (d()->len == d()->left->d()->len + d()->right->d()->len)) || + d()->len == (uint)d()->text->size); + return d()->len; } - struct Data { - union { - mutable QStringData *text; - mutable String *left; - }; - union { - mutable Identifier *identifier; - mutable String *right; - }; - mutable uint stringHash; - mutable uint largestSubLength; - uint len; - }; - Data data; - - const Data *stringData() const { return &data; } - Data *stringData() { return &data; } - - Identifier *identifier() const { return stringData()->identifier; } + Identifier *identifier() const { return d()->identifier; } protected: static void destroy(Managed *); |