From f29bfda2e609f00fad46160495017168094eff7b Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 29 Aug 2011 15:06:14 +1000 Subject: [PATCH] Use the optimized QDeclarativeExpression constructor where possible. Pass in the QDeclarativeScriptString directly, to make use of the precompiled binding. Also does some minor cleanup of the related internal implementation. Change-Id: I4b199298c9da3ee11c51c9c98b384c8324f62c26 Reviewed-on: http://codereview.qt.nokia.com/3696 Reviewed-by: Qt Sanity Bot Reviewed-by: Charles Yin --- src/declarative/qml/qdeclarativebinding.cpp | 2 +- src/declarative/qml/qdeclarativeexpression.cpp | 4 ++-- src/declarative/util/qdeclarativeanimation.cpp | 8 ++------ src/declarative/util/qdeclarativestateoperations.cpp | 8 ++------ 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 0697441..d817990 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -235,7 +235,7 @@ QDeclarativeBinding::createBinding(Identifier id, QObject *obj, QDeclarativeCont QDeclarativeContextData *ctxtdata = QDeclarativeContextData::get(ctxt); - QDeclarativeEnginePrivate *engine = QDeclarativeEnginePrivate::get(qmlEngine(obj)); + QDeclarativeEnginePrivate *engine = QDeclarativeEnginePrivate::get(ctxt->engine()); QDeclarativeCompiledData *cdata = 0; QDeclarativeTypeData *typeData = 0; if (engine && ctxtdata && !ctxtdata->url.isEmpty()) { diff --git a/src/declarative/qml/qdeclarativeexpression.cpp b/src/declarative/qml/qdeclarativeexpression.cpp index 8806996..a24d469 100644 --- a/src/declarative/qml/qdeclarativeexpression.cpp +++ b/src/declarative/qml/qdeclarativeexpression.cpp @@ -242,7 +242,7 @@ QDeclarativeExpression::QDeclarativeExpression(const QDeclarativeScriptString &s } else { QDeclarativeContextData *ctxtdata = QDeclarativeContextData::get(script.context()); - QDeclarativeEnginePrivate *engine = QDeclarativeEnginePrivate::get(qmlEngine(script.scopeObject())); + QDeclarativeEnginePrivate *engine = QDeclarativeEnginePrivate::get(script.context()->engine()); QDeclarativeCompiledData *cdata = 0; QDeclarativeTypeData *typeData = 0; if (engine && ctxtdata && !ctxtdata->url.isEmpty()) { @@ -251,7 +251,7 @@ QDeclarativeExpression::QDeclarativeExpression(const QDeclarativeScriptString &s } if (cdata) - d->init(ctxtdata, cdata->primitives.at(id), cdata, script.scopeObject(), + d->init(ctxtdata, cdata->primitives.at(id), true, script.scopeObject(), cdata->name, script.d.data()->lineNumber); else defaultConstruction = true; diff --git a/src/declarative/util/qdeclarativeanimation.cpp b/src/declarative/util/qdeclarativeanimation.cpp index 11e1c7c..6cdba7c 100644 --- a/src/declarative/util/qdeclarativeanimation.cpp +++ b/src/declarative/util/qdeclarativeanimation.cpp @@ -827,12 +827,8 @@ void QDeclarativeScriptActionPrivate::execute() QDeclarativeScriptString scriptStr = hasRunScriptScript ? runScriptScript : script; - const QString &str = scriptStr.script(); - if (!str.isEmpty()) { - QDeclarativeExpression expr(scriptStr.context(), scriptStr.scopeObject(), str); - QDeclarativeData *ddata = QDeclarativeData::get(q); - if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) - expr.setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); + if (!scriptStr.script().isEmpty()) { + QDeclarativeExpression expr(scriptStr); expr.evaluate(); if (expr.hasError()) qmlInfo(q) << expr.error(); diff --git a/src/declarative/util/qdeclarativestateoperations.cpp b/src/declarative/util/qdeclarativestateoperations.cpp index 6ac2100..98f437d 100644 --- a/src/declarative/util/qdeclarativestateoperations.cpp +++ b/src/declarative/util/qdeclarativestateoperations.cpp @@ -131,12 +131,8 @@ void QDeclarativeStateChangeScript::setName(const QString &n) void QDeclarativeStateChangeScript::execute(Reason) { Q_D(QDeclarativeStateChangeScript); - const QString &script = d->script.script(); - if (!script.isEmpty()) { - QDeclarativeExpression expr(d->script.context(), d->script.scopeObject(), script); - QDeclarativeData *ddata = QDeclarativeData::get(this); - if (ddata && ddata->outerContext && !ddata->outerContext->url.isEmpty()) - expr.setSourceLocation(ddata->outerContext->url.toString(), ddata->lineNumber); + if (!d->script.script().isEmpty()) { + QDeclarativeExpression expr(d->script); expr.evaluate(); if (expr.hasError()) qmlInfo(this, expr.error()); -- 2.7.4