diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-06-23 23:47:25 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-07-02 19:29:52 +0000 |
commit | 32c33ee9abec1ef2f05233c3a613689431f6654b (patch) | |
tree | c5ddd9cae6019ffb052e104b2a24c528460fc01a | |
parent | f1703895e2fc9ec5da3a38a3ffef927a8f4ed86c (diff) |
Get rid of Value::asArrayIndex()
It was only used in a few places now, that can be replaced by
either using a PropertyKey, or by limiting the fast path
optimization in the runtime to array indices smaller than
INT_MAX. Since there are less branches this should even be
faster for pretty much all use cases.
Change-Id: Ib4f2f2f3e27f14ad180b810546e82ac83170b106
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 7 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4runtime.cpp | 15 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value_p.h | 32 |
3 files changed, 11 insertions, 43 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index b42633b446..e3a99e9ddb 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -1398,9 +1398,6 @@ static QV4::ReturnedValue objectFromVariantMap(QV4::ExecutionEngine *e, const QV QV4::ScopedValue v(scope); for (QVariantMap::const_iterator iter = map.begin(), cend = map.end(); iter != cend; ++iter) { s = e->newString(iter.key()); - uint idx = s->asArrayIndex(); - if (idx > 16 && (!o->arrayData() || idx > o->arrayData()->length() * 2)) - o->initSparseArray(); o->put(s, (v = e->fromVariant(iter.value()))); } return o.asReturnedValue(); @@ -1572,11 +1569,13 @@ static QV4::ReturnedValue variantMapToJS(QV4::ExecutionEngine *v4, const QVarian QV4::Scope scope(v4); QV4::ScopedObject o(scope, v4->newObject()); QV4::ScopedString s(scope); + QV4::ScopedPropertyKey key(scope); QV4::ScopedValue v(scope); for (QVariantMap::const_iterator it = vmap.constBegin(), cend = vmap.constEnd(); it != cend; ++it) { s = v4->newIdentifier(it.key()); + key = s->propertyKey(); v = variantToJS(v4, it.value()); - uint idx = s->asArrayIndex(); + uint idx = key->asArrayIndex(); if (idx < UINT_MAX) o->arraySet(idx, v); else diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp index 8a6b011aa2..0f3bd66ba4 100644 --- a/src/qml/jsruntime/qv4runtime.cpp +++ b/src/qml/jsruntime/qv4runtime.cpp @@ -619,7 +619,8 @@ static Q_NEVER_INLINE ReturnedValue getElementIntFallback(ExecutionEngine *engin static Q_NEVER_INLINE ReturnedValue getElementFallback(ExecutionEngine *engine, const Value &object, const Value &index) { - Q_ASSERT(index.asArrayIndex() == UINT_MAX); + Q_ASSERT(!index.isPositiveInt()); + Scope scope(engine); ScopedObject o(scope, object); @@ -641,8 +642,8 @@ static Q_NEVER_INLINE ReturnedValue getElementFallback(ExecutionEngine *engine, ReturnedValue Runtime::method_loadElement(ExecutionEngine *engine, const Value &object, const Value &index) { - uint idx = 0; - if (index.asArrayIndex(idx)) { + if (index.isPositiveInt()) { + uint idx = static_cast<uint>(index.int_32()); if (Heap::Base *b = object.heapObject()) { if (b->internalClass->vtable->isObject) { Heap::Object *o = static_cast<Heap::Object *>(b); @@ -667,8 +668,8 @@ static Q_NEVER_INLINE bool setElementFallback(ExecutionEngine *engine, const Val if (engine->hasException) return false; - uint idx = 0; - if (index.asArrayIndex(idx)) { + if (index.isPositiveInt()) { + uint idx = static_cast<uint>(index.int_32()); if (o->d()->arrayData && o->d()->arrayData->type == Heap::ArrayData::Simple) { Heap::SimpleArrayData *s = o->d()->arrayData.cast<Heap::SimpleArrayData>(); if (idx < s->values.size) { @@ -687,8 +688,8 @@ static Q_NEVER_INLINE bool setElementFallback(ExecutionEngine *engine, const Val void Runtime::method_storeElement(ExecutionEngine *engine, const Value &object, const Value &index, const Value &value) { - uint idx = 0; - if (index.asArrayIndex(idx)) { + if (index.isPositiveInt()) { + uint idx = static_cast<uint>(index.int_32()); if (Heap::Base *b = object.heapObject()) { if (b->internalClass->vtable->isObject) { Heap::Object *o = static_cast<Heap::Object *>(b); diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index ac0a52f7a8..7c9ca9c0bf 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -465,8 +465,6 @@ public: return static_cast<const T *>(managed()); } - inline uint asArrayIndex() const; - inline bool asArrayIndex(uint &idx) const; #ifndef V4_BOOTSTRAP uint asArrayLength(bool *ok) const; #endif @@ -553,36 +551,6 @@ inline double Value::toNumber() const return toNumberImpl(); } - -#ifndef V4_BOOTSTRAP -inline uint Value::asArrayIndex() const -{ - if (Q_LIKELY(isPositiveInt())) { - return (uint)int_32(); - } - if (Q_UNLIKELY(!isDouble())) - return UINT_MAX; - double d = doubleValue(); - uint idx = (uint)d; - if (idx == d) - return idx; - return UINT_MAX; -} - -inline bool Value::asArrayIndex(uint &idx) const -{ - if (Q_LIKELY(isPositiveInt())) { - idx = (uint)int_32(); - return true; - } - if (Q_UNLIKELY(!isDouble())) - return false; - double d = doubleValue(); - idx = (uint)d; - return (idx == d && idx != UINT_MAX); -} -#endif - inline ReturnedValue Heap::Base::asReturnedValue() const { |