diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2025-08-27 14:41:36 +0200 |
|---|---|---|
| committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2025-09-02 12:02:05 +0000 |
| commit | 73723e946af0c3346075df238268210a3937a516 (patch) | |
| tree | c34dd42f9d62480c0717655c1827270ad38305a5 | |
| parent | 1854eebe3eb3a0de501481e08f0f0b58eee1c130 (diff) | |
QtQml: Rephrase Sequence's appendInline()
What we actually want is append default constructed elements. Doing this
the natural way avoids needless complication.
Pick-to: 6.8
Task-number: QTBUG-129972
Task-number: QTBUG-139025
Change-Id: I97318b0e093a76a3d67539ea0d4e28614db4879b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
(cherry picked from commit a99022e243059c564a53978120cfc9bd54289034)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 8642ce05480c0ae61468f41e8c25790390aee52b)
| -rw-r--r-- | src/qml/jsruntime/qv4sequenceobject.cpp | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp index 1521524ae2..8daabe400d 100644 --- a/src/qml/jsruntime/qv4sequenceobject.cpp +++ b/src/qml/jsruntime/qv4sequenceobject.cpp @@ -223,14 +223,14 @@ static void appendInline(Heap::Sequence *p, const QVariant &item) }); } -static void appendInline(Heap::Sequence *p, qsizetype num, const QVariant &item) +static void appendDefaultConstructedInline(Heap::Sequence *p, qsizetype num) { - convertAndDo(item, p->valueMetaType(), [p, num](const void *data) { - const QMetaSequence m = p->metaSequence(); - void *container = p->storagePointer(); - for (qsizetype i = 0; i < num; ++i) - m.addValueAtEnd(container, data); - }); + QVariant item; + const void *data = createVariantData(p->valueMetaType(), &item); + const QMetaSequence m = p->metaSequence(); + void *container = p->storagePointer(); + for (qsizetype i = 0; i < num; ++i) + m.addValueAtEnd(container, data); } static void replaceInline(Heap::Sequence *p, qsizetype index, const QVariant &item) @@ -342,9 +342,7 @@ bool Sequence::virtualPut(Managed *that, PropertyKey id, const Value &value, Val } else { /* according to ECMA262r3 we need to insert */ /* the value at the given index, increasing length to index+1. */ - appendInline( - p, index - count, - valueType == QMetaType::fromType<QVariant>() ? QVariant() : QVariant(valueType)); + appendDefaultConstructedInline(p, index - count); appendInline(p, element); } @@ -504,11 +502,10 @@ QV4::ReturnedValue SequencePrototype::method_setLength( if (newCount == count) { RETURN_UNDEFINED(); } else if (newCount > count) { - const QMetaType valueMetaType = p->valueMetaType(); /* according to ECMA262r3 we need to insert */ /* undefined values increasing length to newLength. */ /* We cannot, so we insert default-values instead. */ - appendInline(p, newCount - count, QVariant(valueMetaType)); + appendDefaultConstructedInline(p, newCount - count); } else { /* according to ECMA262r3 we need to remove */ /* elements until the sequence is the required length. */ |
