From 497ccdc843975bfe20f5b24e083d17f01012efb9 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 10 Apr 2015 12:34:36 +0200 Subject: Speed up binding evaluation Don't spend any cycles of determining the location of the binding (file, line, column) unless we really need that information. That's the case when the profiler is active or an error happens. Change-Id: Iae97808d500b88fed6a813e8b224aa6ebe04d3b6 Reviewed-by: Lars Knoll --- src/qml/debugger/qqmlprofiler_p.h | 8 ++++---- src/qml/jsruntime/qv4functionobject.cpp | 12 ++++++++++++ src/qml/jsruntime/qv4functionobject_p.h | 4 ++++ src/qml/qml/qqmlbinding.cpp | 25 ++----------------------- src/qml/qml/qqmljavascriptexpression.cpp | 9 +++++---- src/qml/qml/qqmljavascriptexpression_p.h | 4 +++- 6 files changed, 30 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/qml/debugger/qqmlprofiler_p.h b/src/qml/debugger/qqmlprofiler_p.h index ba85a76277..5c994b112f 100644 --- a/src/qml/debugger/qqmlprofiler_p.h +++ b/src/qml/debugger/qqmlprofiler_p.h @@ -112,11 +112,11 @@ Q_DECLARE_TYPEINFO(QQmlProfilerData, Q_MOVABLE_TYPE); class QQmlProfiler : public QObject, public QQmlProfilerDefinitions { Q_OBJECT public: - void startBinding(const QString &fileName, int line, int column) + void startBinding(const QQmlSourceLocation &location) { m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), (1 << RangeStart | 1 << RangeLocation), 1 << Binding, - fileName, line, column)); + location.sourceFile, qmlSourceCoordinate(location.line), qmlSourceCoordinate(location.column))); } // Have toByteArrays() construct another RangeData event from the same QString later. @@ -201,11 +201,11 @@ struct QQmlProfilerHelper : public QQmlProfilerDefinitions { }; struct QQmlBindingProfiler : public QQmlProfilerHelper { - QQmlBindingProfiler(QQmlProfiler *profiler, const QString &url, int line, int column) : + QQmlBindingProfiler(QQmlProfiler *profiler, const QV4::FunctionObject *function) : QQmlProfilerHelper(profiler) { Q_QML_PROFILE(QQmlProfilerDefinitions::ProfileBinding, profiler, - startBinding(url, line, column)); + startBinding(function->sourceLocation())); } ~QQmlBindingProfiler() diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp index 5be638e909..f7433e6365 100644 --- a/src/qml/jsruntime/qv4functionobject.cpp +++ b/src/qml/jsruntime/qv4functionobject.cpp @@ -210,6 +210,18 @@ bool FunctionObject::isBoundFunction() const return d()->vtable == BoundFunction::staticVTable(); } +QQmlSourceLocation FunctionObject::sourceLocation() const +{ + if (isBinding()) { + Q_ASSERT(as()); + return static_cast(d())->bindingLocation; + } + QV4::Function *function = d()->function; + Q_ASSERT(function); + + return QQmlSourceLocation(function->sourceFile(), function->compiledFunction->location.line, function->compiledFunction->location.column); +} + DEFINE_OBJECT_VTABLE(FunctionCtor); Heap::FunctionCtor::FunctionCtor(QV4::ExecutionContext *scope) diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h index 3433e7b8ca..560061a705 100644 --- a/src/qml/jsruntime/qv4functionobject_p.h +++ b/src/qml/jsruntime/qv4functionobject_p.h @@ -40,6 +40,8 @@ QT_BEGIN_NAMESPACE +struct QQmlSourceLocation; + namespace QV4 { namespace Heap { @@ -140,6 +142,8 @@ struct Q_QML_EXPORT FunctionObject: Object { bool isBinding() const; bool isBoundFunction() const; + QQmlSourceLocation sourceLocation() const; + static void markObjects(Heap::Base *that, ExecutionEngine *e); }; diff --git a/src/qml/qml/qqmlbinding.cpp b/src/qml/qml/qqmlbinding.cpp index ff794f5f09..0db696394c 100644 --- a/src/qml/qml/qqmlbinding.cpp +++ b/src/qml/qml/qqmlbinding.cpp @@ -165,34 +165,13 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags) if (QQmlData::wasDeleted(object())) return; - QString url; - quint16 lineNumber; - quint16 columnNumber; - QQmlEnginePrivate *ep = QQmlEnginePrivate::get(context()->engine); QV4::Scope scope(ep->v4engine()); QV4::ScopedFunctionObject f(scope, v4function.value()); Q_ASSERT(f); - if (f->isBinding()) { - Q_ASSERT(f->as()); - QQmlSourceLocation loc = static_cast(f->d())->bindingLocation; - url = loc.sourceFile; - lineNumber = loc.line; - columnNumber = loc.column; - } else { - QV4::Function *function = f->asFunctionObject()->function(); - Q_ASSERT(function); - - url = function->sourceFile(); - lineNumber = function->compiledFunction->location.line; - columnNumber = function->compiledFunction->location.column; - } - - int lineNo = qmlSourceCoordinate(lineNumber); - int columnNo = qmlSourceCoordinate(columnNumber); if (!updatingFlag()) { - QQmlBindingProfiler prof(ep->profiler, url, lineNo, columnNo); + QQmlBindingProfiler prof(ep->profiler, f); setUpdatingFlag(true); QQmlAbstractExpression::DeleteWatcher watcher(this); @@ -222,7 +201,7 @@ void QQmlBinding::update(QQmlPropertyPrivate::WriteFlags flags) if (!watcher.wasDeleted()) { if (needsErrorLocationData) - delayedError()->setErrorLocation(QUrl(url), lineNumber, columnNumber); + delayedError()->setErrorLocation(f->sourceLocation()); if (hasError()) { if (!delayedError()->addError(ep)) ep->warning(this->error(context()->engine)); diff --git a/src/qml/qml/qqmljavascriptexpression.cpp b/src/qml/qml/qqmljavascriptexpression.cpp index 3ac0f23e4d..02bd1c4b83 100644 --- a/src/qml/qml/qqmljavascriptexpression.cpp +++ b/src/qml/qml/qqmljavascriptexpression.cpp @@ -40,6 +40,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -59,11 +60,11 @@ bool QQmlDelayedError::addError(QQmlEnginePrivate *e) return true; } -void QQmlDelayedError::setErrorLocation(const QUrl &url, quint16 line, quint16 column) +void QQmlDelayedError::setErrorLocation(const QQmlSourceLocation &sourceLocation) { - m_error.setUrl(url); - m_error.setLine(line); - m_error.setColumn(column); + m_error.setUrl(QUrl(sourceLocation.sourceFile)); + m_error.setLine(sourceLocation.line); + m_error.setColumn(sourceLocation.column); } void QQmlDelayedError::setErrorDescription(const QString &description) diff --git a/src/qml/qml/qqmljavascriptexpression_p.h b/src/qml/qml/qqmljavascriptexpression_p.h index 3f1a8c173d..cbbd88f1fc 100644 --- a/src/qml/qml/qqmljavascriptexpression_p.h +++ b/src/qml/qml/qqmljavascriptexpression_p.h @@ -52,6 +52,8 @@ QT_BEGIN_NAMESPACE +class QQmlSourceLocation; + class QQmlDelayedError { public: @@ -72,7 +74,7 @@ public: inline const QQmlError &error() const { return m_error; } inline void clearError() { m_error = QQmlError(); } - void setErrorLocation(const QUrl &url, quint16 line, quint16 column); + void setErrorLocation(const QQmlSourceLocation &sourceLocation); void setErrorDescription(const QString &description); void setErrorObject(QObject *object); -- cgit v1.2.3