diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-01-04 12:14:23 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-02-09 07:55:36 +0000 |
commit | ea164ca4a8ec1e5c568ab82c0c4256a841f77bf0 (patch) | |
tree | c27efe4df69f429591c0a383b6be999a013a397f /src/qml/jsruntime/qv4internalclass_p.h | |
parent | 394a7c5156162bd7ca1229b033e50c8f56d04069 (diff) |
Change creation of new internal classes
So far we often began with the empty class again when creating
new internal classes. This allowed for multiple paths through the
internal class hierarchy ending up at the same internal class object.
But to be able to efficiently garbage collect internal classes, we
need to have only one path to each instance of an internal class.
Change-Id: Ic6c1f2b3d021e92b44f76a04a8886820e63e8f26
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4internalclass_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4internalclass_p.h | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/qml/jsruntime/qv4internalclass_p.h b/src/qml/jsruntime/qv4internalclass_p.h index 546073dcf5..2597ec9f3f 100644 --- a/src/qml/jsruntime/qv4internalclass_p.h +++ b/src/qml/jsruntime/qv4internalclass_p.h @@ -79,12 +79,12 @@ struct PropertyHash inline PropertyHash(); inline PropertyHash(const PropertyHash &other); inline ~PropertyHash(); + PropertyHash &operator=(const PropertyHash &other); void addEntry(const Entry &entry, int classSize); uint lookup(const Identifier *identifier) const; - -private: - PropertyHash &operator=(const PropertyHash &other); + int removeIdentifier(Identifier *identifier, int classSize); + void detach(bool grow, int classSize); }; struct PropertyHashData @@ -118,6 +118,17 @@ inline PropertyHash::~PropertyHash() delete d; } +inline PropertyHash &PropertyHash::operator=(const PropertyHash &other) +{ + ++other.d->refCount; + if (!--d->refCount) + delete d; + d = other.d; + return *this; +} + + + inline uint PropertyHash::lookup(const Identifier *identifier) const { Q_ASSERT(d->entries); @@ -163,6 +174,13 @@ struct SharedInternalClassData { if (!--d->refcount) delete d; } + SharedInternalClassData &operator=(const SharedInternalClassData &other) { + ++other.d->refcount; + if (!--d->refcount) + delete d; + d = other.d; + return *this; + } void add(uint pos, T value) { if (pos < d->size) { @@ -214,9 +232,6 @@ struct SharedInternalClassData { Q_ASSERT(i < d->size); return d->data[i]; } - -private: - SharedInternalClassData &operator=(const SharedInternalClassData &other); }; struct InternalClassTransition @@ -233,7 +248,8 @@ struct InternalClassTransition NotExtensible = 0x100, VTableChange = 0x200, PrototypeChange = 0x201, - ProtoClass = 0x202 + ProtoClass = 0x202, + RemoveMember = -1 }; bool operator==(const InternalClassTransition &other) const @@ -248,6 +264,7 @@ struct InternalClass : public QQmlJS::Managed { ExecutionEngine *engine; const VTable *vtable; Heap::Object *prototype; + InternalClass *parent = nullptr; PropertyHash propertyTable; // id to valueIndex SharedInternalClassData<Identifier *> nameMap; @@ -309,7 +326,7 @@ private: void updateInternalClassIdRecursive(); friend struct ExecutionEngine; InternalClass(ExecutionEngine *engine); - InternalClass(const InternalClass &other); + InternalClass(InternalClass *other); }; struct InternalClassPool : public QQmlJS::MemoryPool |