From aeb7d3ebbbc5ac16bf7b2f08874f13912b683007 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 3 Nov 2014 02:29:08 +0100 Subject: Move Data for String into the Heap namespace Change-Id: Iefa231106b77db6d4c9d4ded2b028d21eb94ab03 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4context.cpp | 2 +- src/qml/jsruntime/qv4context_p.h | 2 +- src/qml/jsruntime/qv4function.cpp | 2 +- src/qml/jsruntime/qv4identifiertable.cpp | 4 +- src/qml/jsruntime/qv4runtime.cpp | 6 +- src/qml/jsruntime/qv4string.cpp | 44 +++++++-------- src/qml/jsruntime/qv4string_p.h | 95 +++++++++++++++++--------------- 7 files changed, 81 insertions(+), 74 deletions(-) (limited to 'src') diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index cdc82224d7..c9dd694cd3 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -145,7 +145,7 @@ Heap::WithContext::WithContext(ExecutionEngine *engine, QV4::Object *with) withObject = with; } -Heap::CatchContext::CatchContext(ExecutionEngine *engine, String *exceptionVarName, const ValueRef exceptionValue) +Heap::CatchContext::CatchContext(ExecutionEngine *engine, QV4::String *exceptionVarName, const ValueRef exceptionValue) : Heap::ExecutionContext(engine, Heap::ExecutionContext::Type_CatchContext) { strictMode = parent->d()->strictMode; diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h index c7066d8472..281f80bef6 100644 --- a/src/qml/jsruntime/qv4context_p.h +++ b/src/qml/jsruntime/qv4context_p.h @@ -123,7 +123,7 @@ struct GlobalContext : ExecutionContext { }; struct CatchContext : ExecutionContext { - CatchContext(ExecutionEngine *engine, String *exceptionVarName, const ValueRef exceptionValue); + CatchContext(ExecutionEngine *engine, QV4::String *exceptionVarName, const ValueRef exceptionValue); StringValue exceptionVarName; Value exceptionValue; }; diff --git a/src/qml/jsruntime/qv4function.cpp b/src/qml/jsruntime/qv4function.cpp index 6bc48157c0..292244e32a 100644 --- a/src/qml/jsruntime/qv4function.cpp +++ b/src/qml/jsruntime/qv4function.cpp @@ -66,7 +66,7 @@ Function::Function(ExecutionEngine *engine, CompiledData::CompilationUnit *unit, break; } // duplicate arguments, need some trick to store them - arg = (s = engine->memoryManager->alloc(engine, arg, engine->newString(QString(0xfffe))->getPointer())).getPointer(); + arg = (s = engine->memoryManager->alloc(engine, arg->d(), engine->newString(QString(0xfffe))->getPointer()->d())).getPointer(); } } diff --git a/src/qml/jsruntime/qv4identifiertable.cpp b/src/qml/jsruntime/qv4identifiertable.cpp index 5554b68db3..4dca1b65f1 100644 --- a/src/qml/jsruntime/qv4identifiertable.cpp +++ b/src/qml/jsruntime/qv4identifiertable.cpp @@ -69,7 +69,7 @@ void IdentifierTable::addEntry(String *str) { uint hash = str->hashValue(); - if (str->subtype() == String::StringType_ArrayIndex) + if (str->subtype() == Heap::String::StringType_ArrayIndex) return; str->d()->identifier = new Identifier; @@ -133,7 +133,7 @@ Identifier *IdentifierTable::identifierImpl(const String *str) if (str->d()->identifier) return str->d()->identifier; uint hash = str->hashValue(); - if (str->subtype() == String::StringType_ArrayIndex) + if (str->subtype() == Heap::String::StringType_ArrayIndex) return 0; uint idx = hash % alloc; diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 6511e4c2f5..c73d93bc9b 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -507,7 +507,7 @@ QV4::ReturnedValue RuntimeHelpers::addHelper(ExecutionContext *ctx, const ValueR return pright->asReturnedValue(); if (!pright->stringValue()->d()->length()) return pleft->asReturnedValue(); - return (ctx->engine()->memoryManager->alloc(ctx->d()->engine, pleft->stringValue(), pright->stringValue()))->asReturnedValue(); + return (ctx->engine()->memoryManager->alloc(ctx->d()->engine, pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue(); } double x = RuntimeHelpers::toNumber(pleft); double y = RuntimeHelpers::toNumber(pright); @@ -523,7 +523,7 @@ QV4::ReturnedValue Runtime::addString(QV4::ExecutionContext *ctx, const QV4::Val return right->asReturnedValue(); if (!right->stringValue()->d()->length()) return left->asReturnedValue(); - return (ctx->engine()->memoryManager->alloc(ctx->d()->engine, left->stringValue(), right->stringValue()))->asReturnedValue(); + return (ctx->engine()->memoryManager->alloc(ctx->d()->engine, left->stringValue()->d(), right->stringValue()->d()))->asReturnedValue(); } Scope scope(ctx); @@ -540,7 +540,7 @@ QV4::ReturnedValue Runtime::addString(QV4::ExecutionContext *ctx, const QV4::Val return pright->asReturnedValue(); if (!pright->stringValue()->d()->length()) return pleft->asReturnedValue(); - return (ctx->engine()->memoryManager->alloc(ctx->d()->engine, pleft->stringValue(), pright->stringValue()))->asReturnedValue(); + return (ctx->engine()->memoryManager->alloc(ctx->d()->engine, pleft->stringValue()->d(), pright->stringValue()->d()))->asReturnedValue(); } void Runtime::setProperty(ExecutionContext *ctx, const ValueRef object, String *name, const ValueRef value) diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp index 80fbec81cc..945a117364 100644 --- a/src/qml/jsruntime/qv4string.cpp +++ b/src/qml/jsruntime/qv4string.cpp @@ -236,17 +236,17 @@ bool String::isEqualTo(Managed *t, Managed *o) return false; if (that->identifier() && that->identifier() == other->identifier()) return true; - if (that->subtype() >= StringType_UInt && that->subtype() == other->subtype()) + if (that->subtype() >= Heap::String::StringType_UInt && that->subtype() == other->subtype()) return true; return that->toQString() == other->toQString(); } -String::Data::Data(ExecutionEngine *engine, const QString &t) +Heap::String::String(ExecutionEngine *engine, const QString &t) : Heap::Base(engine->stringClass) { - subtype = StringType_Unknown; + subtype = String::StringType_Unknown; text = const_cast(t).data_ptr(); text->ref.ref(); @@ -256,21 +256,21 @@ String::Data::Data(ExecutionEngine *engine, const QString &t) len = text->size; } -String::Data::Data(ExecutionEngine *engine, String *l, String *r) +Heap::String::String(ExecutionEngine *engine, String *l, String *r) : Heap::Base(engine->stringClass) { - subtype = StringType_Unknown; + subtype = String::StringType_Unknown; left = l; right = r; stringHash = UINT_MAX; - largestSubLength = qMax(l->d()->largestSubLength, r->d()->largestSubLength); - len = l->d()->len + r->d()->len; + largestSubLength = qMax(l->largestSubLength, r->largestSubLength); + len = l->len + r->len; - if (!l->d()->largestSubLength && l->d()->len > largestSubLength) - largestSubLength = l->d()->len; - if (!r->d()->largestSubLength && r->d()->len > largestSubLength) - largestSubLength = r->d()->len; + if (!l->largestSubLength && l->len > largestSubLength) + largestSubLength = l->len; + if (!r->largestSubLength && r->len > largestSubLength) + largestSubLength = r->len; // make sure we don't get excessive depth in our strings if (len > 256 && len >= 2*largestSubLength) @@ -281,9 +281,9 @@ uint String::toUInt(bool *ok) const { *ok = true; - if (subtype() == StringType_Unknown) + if (subtype() == Heap::String::StringType_Unknown) createHashValue(); - if (subtype() >= StringType_UInt) + if (subtype() >= Heap::String::StringType_UInt) return d()->stringHash; // ### this conversion shouldn't be required @@ -303,7 +303,7 @@ bool String::equals(String *other) const return false; if (identifier() && identifier() == other->identifier()) return true; - if (subtype() >= StringType_UInt && subtype() == other->subtype()) + if (subtype() >= Heap::String::StringType_UInt && subtype() == other->subtype()) return true; return toQString() == other->toQString(); @@ -317,7 +317,7 @@ void String::makeIdentifierImpl() const engine()->identifierTable->identifier(this); } -void String::Data::simplifyString() const +void Heap::String::simplifyString() const { Q_ASSERT(largestSubLength); @@ -331,19 +331,19 @@ void String::Data::simplifyString() const largestSubLength = 0; } -void String::Data::append(const String::Data *data, QChar *ch) +void Heap::String::append(const String *data, QChar *ch) { - std::vector worklist; + std::vector worklist; worklist.reserve(32); worklist.push_back(data); while (!worklist.empty()) { - const String::Data *item = worklist.back(); + const String *item = worklist.back(); worklist.pop_back(); if (item->largestSubLength) { - worklist.push_back(item->right->d()); - worklist.push_back(item->left->d()); + worklist.push_back(item->right); + worklist.push_back(item->left); } else { memcpy(ch, item->text->data(), item->text->size * sizeof(QChar)); ch += item->text->size; @@ -364,7 +364,7 @@ void String::createHashValue() const bool ok; d()->stringHash = ::toArrayIndex(ch, end, &ok); if (ok) { - setSubtype((d()->stringHash == UINT_MAX) ? StringType_UInt : StringType_ArrayIndex); + setSubtype((d()->stringHash == UINT_MAX) ? Heap::String::StringType_UInt : Heap::String::StringType_ArrayIndex); return; } @@ -375,7 +375,7 @@ void String::createHashValue() const } d()->stringHash = h; - setSubtype(StringType_Regular); + setSubtype(Heap::String::StringType_Regular); } uint String::createHashValue(const QChar *ch, int length) diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h index 9f47327661..69c9a0f892 100644 --- a/src/qml/jsruntime/qv4string_p.h +++ b/src/qml/jsruntime/qv4string_p.h @@ -43,43 +43,10 @@ namespace QV4 { struct ExecutionEngine; struct Identifier; -struct Q_QML_PRIVATE_EXPORT String : public Managed { -#ifndef V4_BOOTSTRAP - struct Q_QML_PRIVATE_EXPORT Data : Heap::Base { - Data(ExecutionEngine *engine, const QString &text); - Data(ExecutionEngine *engine, String *l, String *n); - ~Data() { - if (!largestSubLength && !text->ref.deref()) - QStringData::deallocate(text); - } - void simplifyString() const; - int length() const { - Q_ASSERT((largestSubLength && - (len == left->d()->len + right->d()->len)) || - len == (uint)text->size); - return len; - } - union { - mutable QStringData *text; - mutable String *left; - }; - union { - mutable Identifier *identifier; - mutable String *right; - }; - mutable uint stringHash; - mutable uint largestSubLength; - uint len; - private: - static void append(const Data *data, QChar *ch); - }; - // ### FIXME: Should this be a V4_OBJECT - V4_OBJECT(QV4::Managed) - Q_MANAGED_TYPE(String) - enum { - IsString = true - }; +namespace Heap { +#ifndef V4_BOOTSTRAP +struct Q_QML_PRIVATE_EXPORT String : Base { enum StringType { StringType_Unknown, StringType_Regular, @@ -87,6 +54,46 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { StringType_ArrayIndex }; + String(ExecutionEngine *engine, const QString &text); + String(ExecutionEngine *engine, String *l, String *n); + ~String() { + if (!largestSubLength && !text->ref.deref()) + QStringData::deallocate(text); + } + void simplifyString() const; + int length() const { + Q_ASSERT((largestSubLength && + (len == left->len + right->len)) || + len == (uint)text->size); + return len; + } + union { + mutable QStringData *text; + mutable String *left; + }; + union { + mutable Identifier *identifier; + mutable String *right; + }; + mutable uint stringHash; + mutable uint largestSubLength; + uint len; +private: + static void append(const String *data, QChar *ch); +}; +#endif + +} + +struct Q_QML_PRIVATE_EXPORT String : public Managed { +#ifndef V4_BOOTSTRAP + // ### FIXME: Should this be a V4_OBJECT + V4_OBJECT2(String, Managed) + Q_MANAGED_TYPE(String) + enum { + IsString = true + }; + bool equals(String *other) const; inline bool isEqualTo(const String *other) const { if (this == other) @@ -96,7 +103,7 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { Q_ASSERT(!d()->largestSubLength); if (d()->identifier && d()->identifier == other->d()->identifier) return true; - if (subtype() >= StringType_UInt && subtype() == other->subtype()) + if (subtype() >= Heap::String::StringType_UInt && subtype() == other->subtype()) return true; return toQString() == other->toQString(); @@ -115,17 +122,17 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { } inline unsigned hashValue() const { - if (subtype() == StringType_Unknown) + if (subtype() == Heap::String::StringType_Unknown) createHashValue(); Q_ASSERT(!d()->largestSubLength); return d()->stringHash; } uint asArrayIndex() const { - if (subtype() == StringType_Unknown) + if (subtype() == Heap::String::StringType_Unknown) createHashValue(); Q_ASSERT(!d()->largestSubLength); - if (subtype() == StringType_ArrayIndex) + if (subtype() == Heap::String::StringType_ArrayIndex) return d()->stringHash; return UINT_MAX; } @@ -144,10 +151,10 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed { static uint createHashValue(const char *ch, int length); bool startsWithUpper() const { - const String *l = this; - while (l->d()->largestSubLength) - l = l->d()->left; - return l->d()->text->size && QChar::isUpper(l->d()->text->data()[0]); + const String::Data *l = d(); + while (l->largestSubLength) + l = l->left; + return l->text->size && QChar::isUpper(l->text->data()[0]); } Identifier *identifier() const { return d()->identifier; } -- cgit v1.2.3