diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-01 07:17:37 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-04-01 07:17:37 (GMT) |
commit | 739c1c6a4322c0d48afd2a24e3dc2156fee577e1 (patch) | |
tree | b320072393ec386b96a57d68ab49083d2f4baa78 /src | |
parent | 8907d7cc427e5f1022c6f25944a123e65391c4f2 (diff) | |
download | Qt-739c1c6a4322c0d48afd2a24e3dc2156fee577e1.zip Qt-739c1c6a4322c0d48afd2a24e3dc2156fee577e1.tar.gz Qt-739c1c6a4322c0d48afd2a24e3dc2156fee577e1.tar.bz2 |
Optimization: Only allocate QScriptValue if we need too
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qdeclarativedeclarativedata_p.h | 6 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeengine.cpp | 7 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeobjectscriptclass.cpp | 10 |
3 files changed, 13 insertions, 10 deletions
diff --git a/src/declarative/qml/qdeclarativedeclarativedata_p.h b/src/declarative/qml/qdeclarativedeclarativedata_p.h index dfc3113..aea775b 100644 --- a/src/declarative/qml/qdeclarativedeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedeclarativedata_p.h @@ -75,7 +75,7 @@ public: : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false), context(0), outerContext(0), bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0), - attachedProperties(0), propertyCache(0), guards(0) {} + attachedProperties(0), scriptValue(0), propertyCache(0), guards(0) {} void destroyed(QObject *); void parentChanged(QObject *, QObject *); @@ -113,7 +113,9 @@ public: QHash<int, QObject *> *attachedProperties; - QScriptValue scriptValue; + // ### Can we make this QScriptValuePrivate so we incur no additional allocation + // cost? + QScriptValue *scriptValue; QDeclarativePropertyCache *propertyCache; QDeclarativeGuard<QObject> *guards; diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 65dd72b..cf5fc3b 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -862,15 +862,16 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object) if (ownContext) context->destroy(); + if (scriptValue) + delete scriptValue; + if (ownMemory) delete this; - else - this->~QDeclarativeDeclarativeData(); } void QDeclarativeDeclarativeData::parentChanged(QObject *, QObject *parent) { - if (!parent && scriptValue.isValid()) scriptValue = QScriptValue(); + if (!parent && scriptValue) { delete scriptValue; scriptValue = 0; } } bool QDeclarativeDeclarativeData::hasBindingBit(int bit) const diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index 84c9bef..1424508 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -109,11 +109,11 @@ QScriptValue QDeclarativeObjectScriptClass::newQObject(QObject *object, int type return scriptEngine->undefinedValue(); } else if (!ddata->indestructible && !object->parent()) { return newObject(scriptEngine, this, new ObjectData(object, type)); - } else if (!ddata->scriptValue.isValid()) { - ddata->scriptValue = newObject(scriptEngine, this, new ObjectData(object, type)); - return ddata->scriptValue; - } else if (ddata->scriptValue.engine() == QDeclarativeEnginePrivate::getScriptEngine(engine)) { - return ddata->scriptValue; + } else if (!ddata->scriptValue) { + ddata->scriptValue = new QScriptValue(newObject(scriptEngine, this, new ObjectData(object, type))); + return *ddata->scriptValue; + } else if (ddata->scriptValue->engine() == QDeclarativeEnginePrivate::getScriptEngine(engine)) { + return *ddata->scriptValue; } else { return newObject(scriptEngine, this, new ObjectData(object, type)); } |