diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2025-08-27 11:35:11 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2025-09-01 19:25:20 +0200 |
| commit | 76dccf589d932f04af0faf00613a1951ac0dbd3b (patch) | |
| tree | 37de3b382b47edb56080c96c57d4674146667d4e /src/qml/jsruntime/qv4sequenceobject.cpp | |
| parent | 93a1b24a0463f42048000145d06da272389732bb (diff) | |
QtQml: Refactor QV4::Sequence's raw container operations
We want to encapsulate the container as well as possible.
Pick-to: 6.10 6.9 6.8
Task-number: QTBUG-129972
Task-number: QTBUG-139025
Change-Id: I87841fbe9a9c9f1756eddc979b82ec8b90eec8e2
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4sequenceobject.cpp')
| -rw-r--r-- | src/qml/jsruntime/qv4sequenceobject.cpp | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index e487b17b25..89d4504967 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -387,9 +387,6 @@ bool Sequence::containerIsEqualTo(Managed *other) return false; } -void *Sequence::getRawContainerPtr() const -{ return d()->storagePointer(); } - bool Sequence::loadReference() const { Q_ASSERT(d()->object()); @@ -791,11 +788,51 @@ QVariant SequencePrototype::toVariant(const QV4::Value &array, QMetaType targetT } -void *SequencePrototype::getRawContainerPtr(const Sequence *object, QMetaType typeHint) +static Heap::Sequence *resolveHeapSequence(const Sequence *sequence, QMetaType typeHint) +{ + if (!sequence) + return nullptr; + Heap::Sequence *p = sequence->d(); + if (p->listType() != typeHint) + return nullptr; + return p; +} + +void *SequencePrototype::rawContainerPtr(const Sequence *sequence, QMetaType typeHint) { - if (object->d()->listType() == typeHint) - return object->getRawContainerPtr(); - return nullptr; + Heap::Sequence *p = resolveHeapSequence(sequence, typeHint); + if (!p) + return nullptr; + + return p->storagePointer(); +} + +SequencePrototype::RawCopyResult SequencePrototype::setRawContainer( + Sequence *sequence, const void *container, QMetaType typeHint) +{ + Heap::Sequence *p = resolveHeapSequence(sequence, typeHint); + if (!p) + return TypeMismatch; + + if (typeHint.equals(p->m_container, container)) + return WasEqual; + typeHint.destruct(p->m_container); + typeHint.construct(p->storagePointer(), container); + return Copied; +} + +SequencePrototype::RawCopyResult SequencePrototype::getRawContainer( + const Sequence *sequence, void *container, QMetaType typeHint) +{ + Heap::Sequence *p = resolveHeapSequence(sequence, typeHint); + if (!p) + return TypeMismatch; + + if (typeHint.equals(p->m_container, container)) + return WasEqual; + typeHint.destruct(container); + typeHint.construct(container, p->m_container); + return Copied; } QMetaType SequencePrototype::metaTypeForSequence(const Sequence *object) |
