aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4sequenceobject.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-08-27 14:41:36 +0200
committerUlf Hermann <ulf.hermann@qt.io>2025-09-01 19:25:21 +0200
commita99022e243059c564a53978120cfc9bd54289034 (patch)
tree0c50c504c5907e22f4cd7115fc3666cf0d06aefa /src/qml/jsruntime/qv4sequenceobject.cpp
parent2aeafa46990c4211ece4ee173de69ec2b88577ac (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.10 6.9 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>
Diffstat (limited to 'src/qml/jsruntime/qv4sequenceobject.cpp')
-rw-r--r--src/qml/jsruntime/qv4sequenceobject.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/qml/jsruntime/qv4sequenceobject.cpp b/src/qml/jsruntime/qv4sequenceobject.cpp
index 3d203d91d4..d9fab3cda9 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. */