diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-11-02 18:48:18 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-25 22:04:42 +0100 |
commit | a41764cafbc85c271edde8d09eae46798ccdcb8d (patch) | |
tree | cb027ea57c6f764bdc277bf899caa3f8a866647b /src/qml/qml/qqmlcontextwrapper.cpp | |
parent | 62c906059516bb829f05073096fd3e12f5103fba (diff) |
IR Cleanup, resolve ID objects through array subscripts
...instead of a special MEMBER type. This allows removing the
type member from V4IR::Member altogether (and thus unshadow from
V4IR::Expr::type). By not requiring the base of a id lookup
member expression to be a NAME, we can also speed up repeated
id lookups by fetching the id object array wrapper only once
per function.
Change-Id: I3e9b8f498d32ace4a0cc2254f49e02ecc124f79c
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlcontextwrapper.cpp')
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 406826a6f6..cbfc5468fe 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -63,7 +63,7 @@ DEFINE_MANAGED_VTABLE(QmlContextWrapper); QmlContextWrapper::QmlContextWrapper(QV8Engine *engine, QQmlContextData *context, QObject *scopeObject, bool ownsContext) : Object(QV8Engine::getV4(engine)), v8(engine), readOnly(true), ownsContext(ownsContext), isNullWrapper(false), - context(context), scopeObject(scopeObject) + context(context), scopeObject(scopeObject), idObjectsWrapper(0) { vtbl = &static_vtbl; } @@ -355,6 +355,14 @@ void QmlContextWrapper::destroy(Managed *that) static_cast<QmlContextWrapper *>(that)->~QmlContextWrapper(); } +void QmlContextWrapper::markObjects(Managed *m, ExecutionEngine *engine) +{ + QmlContextWrapper *This = static_cast<QmlContextWrapper*>(m); + if (This->idObjectsWrapper) + This->idObjectsWrapper->mark(engine); + Object::markObjects(m, engine); +} + void QmlContextWrapper::registerQmlDependencies(ExecutionEngine *engine, const CompiledData::Function *compiledFunction) { // Let the caller check and avoid the function call :) @@ -395,4 +403,52 @@ void QmlContextWrapper::registerQmlDependencies(ExecutionEngine *engine, const C } +ReturnedValue QmlContextWrapper::idObjectsArray() +{ + if (!idObjectsWrapper) { + ExecutionEngine *v4 = engine(); + idObjectsWrapper = new (v4->memoryManager) QQmlIdObjectsArray(v4, this); + } + return idObjectsWrapper->asReturnedValue(); +} + +DEFINE_MANAGED_VTABLE(QQmlIdObjectsArray); + +QQmlIdObjectsArray::QQmlIdObjectsArray(ExecutionEngine *engine, QmlContextWrapper *contextWrapper) + : Object(engine) + , contextWrapper(contextWrapper) +{ + vtbl = &static_vtbl; +} + +ReturnedValue QQmlIdObjectsArray::getIndexed(Managed *m, uint index, bool *hasProperty) +{ + QQmlIdObjectsArray *This = static_cast<QQmlIdObjectsArray*>(m); + QQmlContextData *context = This->contextWrapper->getContext(); + if (!context) { + if (hasProperty) + *hasProperty = false; + return Encode::undefined(); + } + if (index >= (uint)context->idValueCount) { + if (hasProperty) + *hasProperty = false; + return Encode::undefined(); + } + + ExecutionEngine *v4 = m->engine(); + QQmlEnginePrivate *ep = v4->v8Engine->engine() ? QQmlEnginePrivate::get(v4->v8Engine->engine()) : 0; + if (ep) + ep->captureProperty(&context->idValues[index].bindings); + + return QObjectWrapper::wrap(This->engine(), context->idValues[index].data()); +} + +void QQmlIdObjectsArray::markObjects(Managed *that, ExecutionEngine *engine) +{ + QQmlIdObjectsArray *This = static_cast<QQmlIdObjectsArray*>(that); + This->contextWrapper->mark(engine); + Object::markObjects(that, engine); +} + QT_END_NAMESPACE |