From 06e3cfb0c49ca94d4456d7abc8b332ef9582ae62 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 14 Oct 2016 12:06:23 +0200 Subject: QML: Split two QQmlData methods into fast/slow paths The common case is that the property cache and the QQmlData itself are already created. By splitting the creation off into a slow-path method, these simple methods are cheap to inline. Change-Id: I73c702b5e66f35379647946a0c431561fd87499b Reviewed-by: Simon Hausmann --- src/qml/qml/qqmldata_p.h | 15 ++++++++++++--- src/qml/qml/qqmlengine.cpp | 18 +++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/qml/qml') diff --git a/src/qml/qml/qqmldata_p.h b/src/qml/qml/qqmldata_p.h index dce75c51aa..e271598c2d 100644 --- a/src/qml/qml/qqmldata_p.h +++ b/src/qml/qml/qqmldata_p.h @@ -207,8 +207,7 @@ public: } else if (priv->declarativeData) { return static_cast(priv->declarativeData); } else if (create) { - priv->declarativeData = new QQmlData; - return static_cast(priv->declarativeData); + return createQQmlData(priv); } else { return 0; } @@ -231,12 +230,22 @@ public: static inline void flushPendingBinding(QObject *, QQmlPropertyIndex propertyIndex); - static QQmlPropertyCache *ensurePropertyCache(QJSEngine *engine, QObject *object); + static QQmlPropertyCache *ensurePropertyCache(QJSEngine *engine, QObject *object) + { + Q_ASSERT(engine); + QQmlData *ddata = QQmlData::get(object, /*create*/true); + if (Q_LIKELY(ddata->propertyCache)) + return ddata->propertyCache; + return createPropertyCache(engine, object); + } private: // For attachedProperties mutable QQmlDataExtended *extendedData; + Q_NEVER_INLINE static QQmlData *createQQmlData(QObjectPrivate *priv); + Q_NEVER_INLINE static QQmlPropertyCache *createPropertyCache(QJSEngine *engine, QObject *object); + void flushPendingBindingImpl(QQmlPropertyIndex index); Q_ALWAYS_INLINE bool hasBitSet(int bit) const diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index c10aa0129c..7877ee7e21 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -1861,15 +1861,19 @@ void QQmlData::setPendingBindingBit(QObject *obj, int coreIndex) QQmlData_setBit(this, obj, coreIndex * 2 + 1); } -QQmlPropertyCache *QQmlData::ensurePropertyCache(QJSEngine *engine, QObject *object) +QQmlData *QQmlData::createQQmlData(QObjectPrivate *priv) +{ + Q_ASSERT(priv); + priv->declarativeData = new QQmlData; + return static_cast(priv->declarativeData); +} + +QQmlPropertyCache *QQmlData::createPropertyCache(QJSEngine *engine, QObject *object) { - Q_ASSERT(engine); QQmlData *ddata = QQmlData::get(object, /*create*/true); - if (!ddata->propertyCache) { - ddata->propertyCache = QJSEnginePrivate::get(engine)->cache(object); - if (ddata->propertyCache) - ddata->propertyCache->addref(); - } + ddata->propertyCache = QJSEnginePrivate::get(engine)->cache(object); + if (ddata->propertyCache) + ddata->propertyCache->addref(); return ddata->propertyCache; } -- cgit v1.2.3