diff options
author | Michael Brasser <michael.brasser@live.com> | 2014-03-03 12:06:51 -0600 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-04 10:26:10 +0100 |
commit | 17eaab833cb303caf3f99a0cf9f98e7edc47b0f9 (patch) | |
tree | b8832f3133625b02fc1a0b84edca3248b4dc8df3 /src/qml/qml/qqmlboundsignal.cpp | |
parent | 72293bf3b0a6a3d6ac30cf472b81fd4844b3d582 (diff) |
Reduce size of QQmlBoundSignalExpression in the common case.
This reduces the base size of QQmlBoundSignalExpression by 20 bytes,
by moving member variables specific to runtime rewrites in to an "extra"
structure.
Task-number: QTBUG-37134
Change-Id: I235895a395ba4304a7ea071d88aa9aebcfff61cb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/qml/qqmlboundsignal.cpp')
-rw-r--r-- | src/qml/qml/qqmlboundsignal.cpp | 97 |
1 files changed, 70 insertions, 27 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp index e5a0df8c32..8c3e1c7384 100644 --- a/src/qml/qml/qqmlboundsignal.cpp +++ b/src/qml/qml/qqmlboundsignal.cpp @@ -66,36 +66,44 @@ static QQmlJavaScriptExpression::VTable QQmlBoundSignalExpression_jsvtable = { QQmlBoundSignalExpression::expressionChanged }; +QQmlBoundSignalExpression::ExtraData::ExtraData(const QString &handlerName, const QString ¶meterString, + const QString &expression, const QString &fileName, + quint16 line, quint16 column) + : m_handlerName(handlerName), + m_parameterString(parameterString), + m_expression(expression), + m_fileName(fileName), + m_line(line), + m_column(column) +{ +} + QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scope, const QString &expression, const QString &fileName, quint16 line, quint16 column, const QString &handlerName, const QString ¶meterString) : QQmlJavaScriptExpression(&QQmlBoundSignalExpression_jsvtable), - m_fileName(fileName), - m_line(line), - m_column(column), m_target(target), m_index(index), - m_expressionFunctionValid(false), - m_invalidParameterName(false) + m_extra(new ExtraData(handlerName, parameterString, expression, fileName, line, column)) { + setExpressionFunctionValid(false); + setInvalidParameterName(false); + init(ctxt, scope); - m_handlerName = handlerName; - m_parameterString = parameterString; - m_expression = expression; } QQmlBoundSignalExpression::QQmlBoundSignalExpression(QObject *target, int index, QQmlContextData *ctxt, QObject *scope, const QV4::ValueRef &function) : QQmlJavaScriptExpression(&QQmlBoundSignalExpression_jsvtable), m_v8function(function), - m_line(USHRT_MAX), - m_column(USHRT_MAX), m_target(target), m_index(index), - m_expressionFunctionValid(true), - m_invalidParameterName(false) + m_extra(0) { + setExpressionFunctionValid(true); + setInvalidParameterName(false); + init(ctxt, scope); } @@ -124,21 +132,55 @@ void QQmlBoundSignalExpression::expressionChanged(QQmlJavaScriptExpression *) // bound signals do not notify on change. } +QString QQmlBoundSignalExpression::sourceFile() const +{ + if (expressionFunctionValid()) { + QV4::Function *f = function(); + Q_ASSERT(f); + return f->sourceFile(); + } + 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; +} + QString QQmlBoundSignalExpression::expression() const { - if (m_expressionFunctionValid) { + if (expressionFunctionValid()) { Q_ASSERT (context() && engine()); QV4::Scope scope(QQmlEnginePrivate::get(engine())->v4engine()); QV4::ScopedValue v(scope, m_v8function.value()); return v->toQStringNoThrow(); } else { - return m_expression; + Q_ASSERT(!m_extra.isNull()); + return m_extra->m_expression; } } QV4::Function *QQmlBoundSignalExpression::function() const { - if (m_expressionFunctionValid) { + if (expressionFunctionValid()) { Q_ASSERT (context() && engine()); QV4::Scope scope(QQmlEnginePrivate::get(engine())->v4engine()); QV4::Scoped<QV4::FunctionObject> v(scope, m_v8function.value()); @@ -153,7 +195,7 @@ void QQmlBoundSignalExpression::evaluate(void **a) { Q_ASSERT (context() && engine()); - if (m_invalidParameterName) + if (invalidParameterName()) return; QQmlEnginePrivate *ep = QQmlEnginePrivate::get(engine()); @@ -161,14 +203,15 @@ void QQmlBoundSignalExpression::evaluate(void **a) ep->referenceScarceResources(); // "hold" scarce resources in memory during evaluation. { - if (!m_expressionFunctionValid) { + if (!expressionFunctionValid()) { + Q_ASSERT(!m_extra.isNull()); QString expression; expression = QStringLiteral("(function "); - expression += m_handlerName; + expression += m_extra->m_handlerName; expression += QLatin1Char('('); - if (m_parameterString.isEmpty()) { + if (m_extra->m_parameterString.isEmpty()) { QString error; //TODO: look at using the property cache here (as in the compiler) // for further optimization @@ -177,30 +220,30 @@ void QQmlBoundSignalExpression::evaluate(void **a) if (!error.isEmpty()) { qmlInfo(scopeObject()) << error; - m_invalidParameterName = true; + setInvalidParameterName(true); ep->dereferenceScarceResources(); return; } } else - expression += m_parameterString; + expression += m_extra->m_parameterString; expression += QStringLiteral(") { "); - expression += m_expression; + expression += m_extra->m_expression; expression += QStringLiteral(" })"); - m_expression.clear(); - m_handlerName.clear(); - m_parameterString.clear(); + m_extra->m_expression.clear(); + m_extra->m_handlerName.clear(); + m_extra->m_parameterString.clear(); m_v8function = evalFunction(context(), scopeObject(), expression, - m_fileName, m_line, &m_v8qmlscope); + m_extra->m_fileName, m_extra->m_line, &m_v8qmlscope); if (m_v8function.isNullOrUndefined()) { ep->dereferenceScarceResources(); return; // could not evaluate function. Not valid. } - m_expressionFunctionValid = true; + setExpressionFunctionValid(true); } QV8Engine *engine = ep->v8engine(); |