From db1034d093d76b4b6e66fcdd178800e0cf9d1005 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 23 Jun 2017 12:10:23 +0200 Subject: Move the engine pointer from the property cache to the VME meta object This is where it belongs, and it makes the PropertyCache independent of the engine used. Task-number: QTBUG-61536 Change-Id: I21c2674ee3e2895abd2418764d140b154b47b868 Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlpropertycache.cpp | 42 +++++++++++---------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) (limited to 'src/qml/qml/qqmlpropertycache.cpp') diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index d18159841c..9a495e6fa3 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -99,7 +99,7 @@ static QQmlPropertyData::Flags fastFlagsForProperty(const QMetaProperty &p) // Flags that do depend on the property's QMetaProperty::userType() and thus are slow to // load -static void flagsForPropertyType(int propType, QQmlEngine *engine, QQmlPropertyData::Flags &flags) +static void flagsForPropertyType(int propType, QQmlPropertyData::Flags &flags) { Q_ASSERT(propType != -1); @@ -116,9 +116,7 @@ static void flagsForPropertyType(int propType, QQmlEngine *engine, QQmlPropertyD } else if (propType == qMetaTypeId()) { flags.type = QQmlPropertyData::Flags::V4HandleType; } else { - QQmlMetaType::TypeCategory cat = - engine ? QQmlEnginePrivate::get(engine)->typeCategory(propType) - : QQmlMetaType::typeCategory(propType); + QQmlMetaType::TypeCategory cat = QQmlMetaType::typeCategory(propType); if (cat == QQmlMetaType::Object || QMetaType::typeFlags(propType) & QMetaType::PointerToQObject) flags.type = QQmlPropertyData::Flags::QObjectDerivedType; @@ -136,10 +134,10 @@ static int metaObjectSignalCount(const QMetaObject *metaObject) } QQmlPropertyData::Flags -QQmlPropertyData::flagsForProperty(const QMetaProperty &p, QQmlEngine *engine) +QQmlPropertyData::flagsForProperty(const QMetaProperty &p) { auto flags = fastFlagsForProperty(p); - flagsForPropertyType(p.userType(), engine, flags); + flagsForPropertyType(p.userType(), flags); return flags; } @@ -166,13 +164,13 @@ void QQmlPropertyData::lazyLoad(const QMetaProperty &p) } } -void QQmlPropertyData::load(const QMetaProperty &p, QQmlEngine *engine) +void QQmlPropertyData::load(const QMetaProperty &p) { setPropType(p.userType()); setCoreIndex(p.propertyIndex()); setNotifyIndex(QMetaObjectPrivate::signalIndex(p.notifySignal())); setFlags(fastFlagsForProperty(p)); - flagsForPropertyType(propType(), engine, _flags); + flagsForPropertyType(propType(), _flags); Q_ASSERT(p.revision() <= Q_INT16_MAX); setRevision(p.revision()); } @@ -244,19 +242,18 @@ void QQmlPropertyData::lazyLoad(const QMetaMethod &m) /*! Creates a new empty QQmlPropertyCache. */ -QQmlPropertyCache::QQmlPropertyCache(QV4::ExecutionEngine *e) - : engine(e), _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0), +QQmlPropertyCache::QQmlPropertyCache() + : _parent(0), propertyIndexCacheStart(0), methodIndexCacheStart(0), signalHandlerIndexCacheStart(0), _hasPropertyOverrides(false), _ownMetaObject(false), _metaObject(0), argumentsCache(0), _jsFactoryMethodIndex(-1) { - Q_ASSERT(engine); } /*! Creates a new QQmlPropertyCache of \a metaObject. */ -QQmlPropertyCache::QQmlPropertyCache(QV4::ExecutionEngine *e, const QMetaObject *metaObject) - : QQmlPropertyCache(e) +QQmlPropertyCache::QQmlPropertyCache(const QMetaObject *metaObject) + : QQmlPropertyCache() { Q_ASSERT(metaObject); @@ -265,8 +262,6 @@ QQmlPropertyCache::QQmlPropertyCache(QV4::ExecutionEngine *e, const QMetaObject QQmlPropertyCache::~QQmlPropertyCache() { - clear(); - QQmlPropertyCacheMethodArguments *args = argumentsCache; while (args) { QQmlPropertyCacheMethodArguments *next = args->next; @@ -284,24 +279,11 @@ QQmlPropertyCache::~QQmlPropertyCache() if (_ownMetaObject) free(const_cast(_metaObject)); _metaObject = 0; _parent = 0; - engine = 0; -} - -void QQmlPropertyCache::destroy() -{ - delete this; -} - -// This is inherited from QQmlCleanup, so it should only clear the things -// that are tied to the specific QQmlEngine. -void QQmlPropertyCache::clear() -{ - engine = 0; } QQmlPropertyCache *QQmlPropertyCache::copy(int reserve) { - QQmlPropertyCache *cache = new QQmlPropertyCache(engine); + QQmlPropertyCache *cache = new QQmlPropertyCache(); cache->_parent = this; cache->_parent->addref(); cache->propertyIndexCacheStart = propertyIndexCache.count() + propertyIndexCacheStart; @@ -711,7 +693,7 @@ void QQmlPropertyCache::resolve(QQmlPropertyData *data) const data->setPropType(registerResult == -1 ? QMetaType::UnknownType : registerResult); } } - flagsForPropertyType(data->propType(), engine->qmlEngine(), data->_flags); + flagsForPropertyType(data->propType(), data->_flags); } } -- cgit v1.2.3 From 2aabfa28a5fa4a7a0a5c5f47872df19f84551fab Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 20 Jul 2017 11:42:45 +0200 Subject: Avoid meta-object creation when looking up QML properties in the property cache When looking up QML properties in the property cache, we also need to verify that they should be visible in the QML context they are requested from, i.e. if the revision of the object in that context has the property visible or not. That requires retrieving the VME meta-object for QML declared properties. We can retrieve that directly from the QObjectPrivate instead of going through the potential meta-object builder creation path. Task-number: QTBUG-61536 Change-Id: I695921d625169de5c58941087464beb5367fb2db Reviewed-by: Lars Knoll --- src/qml/qml/qqmlpropertycache.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/qml/qml/qqmlpropertycache.cpp') diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp index 9a495e6fa3..019fa654d1 100644 --- a/src/qml/qml/qqmlpropertycache.cpp +++ b/src/qml/qml/qqmlpropertycache.cpp @@ -764,7 +764,11 @@ void QQmlPropertyCache::invalidate(const QMetaObject *metaObject) QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, QObject *object, QQmlContextData *context) const { QQmlData *data = (object ? QQmlData::get(object) : 0); - const QQmlVMEMetaObject *vmemo = (data && data->hasVMEMetaObject ? static_cast(object->metaObject()) : 0); + const QQmlVMEMetaObject *vmemo = 0; + if (data && data->hasVMEMetaObject) { + QObjectPrivate *op = QObjectPrivate::get(object); + vmemo = static_cast(op->metaObject); + } return findProperty(it, vmemo, context); } @@ -808,9 +812,9 @@ QQmlPropertyData *QQmlPropertyCache::findProperty(StringCache::ConstIterator it, } if (vmemo) { - const int methodCount = vmemo->methodCount(); - const int signalCount = vmemo->signalCount(); - const int propertyCount = vmemo->propertyCount(); + const int methodCount = vmemo->cache->methodCount(); + const int signalCount = vmemo->cache->signalCount(); + const int propertyCount = vmemo->cache->propertyCount(); // Ensure that the property we resolve to is accessible from this meta-object do { -- cgit v1.2.3