aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-03-04 09:45:13 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-04 15:22:58 +0100
commit588da94cce7ee0d9e03908fd5be211a5b629511c (patch)
tree70f9077e90e3254979280860373bc511397d78e3 /src
parent94d003c59b346c078e4aa8233c29c2c2c3467e3b (diff)
Combine the source file, line and column number triplet in a common structure
This avoids unnecessary function calls when all of the three pieces need to be retrieved from a QQmlBoundSignalExpression. Change-Id: Ibcd498c907ea723baf6439cf32ca5fc704f204b5 Reviewed-by: Ulf Hermann <ulf.hermann@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/debugger/qqmlprofiler_p.h18
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp41
-rw-r--r--src/qml/qml/qqmlboundsignal_p.h8
-rw-r--r--src/qml/qml/qqmlengine.cpp10
-rw-r--r--src/qml/qml/qqmlglobal_p.h10
5 files changed, 31 insertions, 56 deletions
diff --git a/src/qml/debugger/qqmlprofiler_p.h b/src/qml/debugger/qqmlprofiler_p.h
index 27d4b58db6..6afdc1e73b 100644
--- a/src/qml/debugger/qqmlprofiler_p.h
+++ b/src/qml/debugger/qqmlprofiler_p.h
@@ -135,11 +135,11 @@ public:
1 << Compiling, name, 1, 1));
}
- void startHandlingSignal(const QString &fileName, int line, int column)
+ void startHandlingSignal(const QQmlSourceLocation &location)
{
m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(),
(1 << RangeStart | 1 << RangeLocation), 1 << HandlingSignal,
- fileName, line, column));
+ location.sourceFile, location.line, location.column));
}
void startCreating(const QString &typeName, const QUrl &fileName, int line, int column)
@@ -224,19 +224,7 @@ struct QQmlHandlingSignalProfiler : public QQmlProfilerHelper {
QQmlHandlingSignalProfiler(QQmlProfiler *profiler, QQmlBoundSignalExpression *expression) :
QQmlProfilerHelper(profiler)
{
- Q_QML_PROFILE_IF_ENABLED(profiler, {
- QV4::Function *function;
- if (expression->sourceFile().isEmpty() && (function = expression->function())) {
- profiler->startHandlingSignal(
- function->sourceFile(), function->compiledFunction->location.line,
- function->compiledFunction->location.column);
-
- } else {
- profiler->startHandlingSignal(
- expression->sourceFile(), expression->lineNumber(),
- expression->columnNumber());
- }
- });
+ Q_QML_PROFILE(profiler, startHandlingSignal(expression->sourceLocation()));
}
~QQmlHandlingSignalProfiler()
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index 8c3e1c7384..f7ece53121 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -72,9 +72,7 @@ QQmlBoundSignalExpression::ExtraData::ExtraData(const QString &handlerName, cons
: m_handlerName(handlerName),
m_parameterString(parameterString),
m_expression(expression),
- m_fileName(fileName),
- m_line(line),
- m_column(column)
+ m_sourceLocation(fileName, line, column)
{
}
@@ -124,7 +122,8 @@ QQmlBoundSignalExpression::~QQmlBoundSignalExpression()
QString QQmlBoundSignalExpression::expressionIdentifier(QQmlJavaScriptExpression *e)
{
QQmlBoundSignalExpression *This = static_cast<QQmlBoundSignalExpression *>(e);
- return This->sourceFile() + QLatin1Char(':') + QString::number(This->lineNumber());
+ QQmlSourceLocation loc = This->sourceLocation();
+ return loc.sourceFile + QLatin1Char(':') + QString::number(loc.line);
}
void QQmlBoundSignalExpression::expressionChanged(QQmlJavaScriptExpression *)
@@ -132,37 +131,19 @@ void QQmlBoundSignalExpression::expressionChanged(QQmlJavaScriptExpression *)
// bound signals do not notify on change.
}
-QString QQmlBoundSignalExpression::sourceFile() const
+QQmlSourceLocation QQmlBoundSignalExpression::sourceLocation() const
{
if (expressionFunctionValid()) {
QV4::Function *f = function();
Q_ASSERT(f);
- return f->sourceFile();
+ QQmlSourceLocation loc;
+ loc.sourceFile = f->sourceFile();
+ loc.line = f->compiledFunction->location.line;
+ loc.column = f->compiledFunction->location.column;
+ return loc;
}
Q_ASSERT(!m_extra.isNull());
- return m_extra->m_fileName;
-}
-
-quint16 QQmlBoundSignalExpression::lineNumber() const
-{
- if (expressionFunctionValid()) {
- QV4::Function *f = function();
- Q_ASSERT(f);
- return f->compiledFunction->location.line;
- }
- Q_ASSERT(!m_extra.isNull());
- return m_extra->m_line;
-}
-
-quint16 QQmlBoundSignalExpression::columnNumber() const
-{
- if (expressionFunctionValid()) {
- QV4::Function *f = function();
- Q_ASSERT(f);
- return f->compiledFunction->location.column;
- }
- Q_ASSERT(!m_extra.isNull());
- return m_extra->m_column;
+ return m_extra->m_sourceLocation;
}
QString QQmlBoundSignalExpression::expression() const
@@ -236,7 +217,7 @@ void QQmlBoundSignalExpression::evaluate(void **a)
m_extra->m_parameterString.clear();
m_v8function = evalFunction(context(), scopeObject(), expression,
- m_extra->m_fileName, m_extra->m_line, &m_v8qmlscope);
+ m_extra->m_sourceLocation.sourceFile, m_extra->m_sourceLocation.line, &m_v8qmlscope);
if (m_v8function.isNullOrUndefined()) {
ep->dereferenceScarceResources();
diff --git a/src/qml/qml/qqmlboundsignal_p.h b/src/qml/qml/qqmlboundsignal_p.h
index 93cff745e2..6df6da4214 100644
--- a/src/qml/qml/qqmlboundsignal_p.h
+++ b/src/qml/qml/qqmlboundsignal_p.h
@@ -86,9 +86,7 @@ public:
// evaluation of a bound signal expression doesn't return any value
void evaluate(void **a);
- QString sourceFile() const;
- quint16 lineNumber() const;
- quint16 columnNumber() const;
+ QQmlSourceLocation sourceLocation() const;
QString expression() const;
QV4::Function *function() const;
QObject *target() const { return m_target; }
@@ -120,9 +118,7 @@ private:
QString m_handlerName;
QString m_parameterString;
QString m_expression;
- QString m_fileName;
- quint16 m_line;
- quint16 m_column;
+ QQmlSourceLocation m_sourceLocation;
};
// We store some flag bits in the following flag pointers.
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp
index 6554ddc740..e9a0858474 100644
--- a/src/qml/qml/qqmlengine.cpp
+++ b/src/qml/qml/qqmlengine.cpp
@@ -1617,11 +1617,11 @@ void QQmlData::destroyed(QObject *object)
QString locationString;
QQmlBoundSignalExpression *expr = signalHandler->expression();
if (expr) {
- QString fileName = expr->sourceFile();
- if (fileName.isEmpty())
- fileName = QStringLiteral("<Unknown File>");
- locationString.append(fileName);
- locationString.append(QString::fromLatin1(":%0: ").arg(expr->lineNumber()));
+ QQmlSourceLocation location = expr->sourceLocation();
+ if (location.sourceFile.isEmpty())
+ location.sourceFile = QStringLiteral("<Unknown File>");
+ locationString.append(location.sourceFile);
+ locationString.append(QString::fromLatin1(":%0: ").arg(location.line));
QString source = expr->expression();
if (source.size() > 100) {
source.truncate(96);
diff --git a/src/qml/qml/qqmlglobal_p.h b/src/qml/qml/qqmlglobal_p.h
index eca13e8fb8..8a17c81895 100644
--- a/src/qml/qml/qqmlglobal_p.h
+++ b/src/qml/qml/qqmlglobal_p.h
@@ -368,6 +368,16 @@ public:
QStringList args;
};
+struct QQmlSourceLocation
+{
+ QQmlSourceLocation() : line(0), column(0) {}
+ QQmlSourceLocation(const QString &sourceFile, quint16 line, quint16 column)
+ : sourceFile(sourceFile), line(line), column(column) {}
+ QString sourceFile;
+ quint16 line;
+ quint16 column;
+};
+
QT_END_NAMESPACE
#endif // QQMLGLOBAL_H