aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4runtime.cpp
diff options
context:
space:
mode:
authorLars Knoll <[email protected]>2014-01-24 12:46:28 +0100
committerThe Qt Project <[email protected]>2014-01-31 11:13:48 +0100
commite3219a1f7143c52fad7f5c5266327e199d02c6d6 (patch)
tree540610679e7a7548b74f7599b58bcc45ca994cc3 /src/qml/jsruntime/qv4runtime.cpp
parentb8eaedb0dcf0daeae55fd2c2c6e31588c43613bf (diff)
Fix a bug in qmljs_set_element and improve it's performance
Avoid expensive function calls for setting indexed properties in the common case. The spec requires us to read the value before writing it to check whether it's empty. In that case we need to fall back to the slow implementation that checks the proto chain. Change-Id: If278ba81f170d35c18135d2f8661459262e7e606 Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4runtime.cpp')
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index c929b39e6a..a991940c6b 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -613,10 +613,14 @@ void __qmljs_set_element(ExecutionContext *ctx, const ValueRef object, const Val
uint idx = index->asArrayIndex();
if (idx < UINT_MAX) {
- if (o->arrayType() == ArrayData::Simple && idx < o->arrayData->length())
- o->arrayPut(idx, value);
- else
- o->putIndexed(idx, value);
+ if (o->arrayType() == ArrayData::Simple) {
+ SimpleArrayData *s = static_cast<SimpleArrayData *>(o->arrayData);
+ if (s && idx < s->len && !s->data[idx].isEmpty()) {
+ s->data[idx] = value;
+ return;
+ }
+ }
+ o->putIndexed(idx, value);
return;
}