aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlboundsignal.cpp
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2012-05-14 15:51:28 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-18 02:24:35 +0200
commit2d2580838d580edbac22a2cf906a4d6da2d670ef (patch)
tree33dedd58a0e06b5e93386c867667a67b82672169 /src/qml/qml/qqmlboundsignal.cpp
parent4c9b4c951934a3ba277dcbf565215305a27d2e06 (diff)
Improve memory usage of Connections and signal handlers.
Following the pattern of 330152354aed8496ac78d145e14b25ee2d7bf8fb, store the source as Utf8. Keep one less copy of the source when possible. Change-Id: Ifa5f5fdc9ea3d48e904489dc262145eff36e710c Reviewed-by: Chris Adams <christopher.adams@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlboundsignal.cpp')
-rw-r--r--src/qml/qml/qqmlboundsignal.cpp41
1 files changed, 31 insertions, 10 deletions
diff --git a/src/qml/qml/qqmlboundsignal.cpp b/src/qml/qml/qqmlboundsignal.cpp
index 629c8a52b7..8f15e0aa80 100644
--- a/src/qml/qml/qqmlboundsignal.cpp
+++ b/src/qml/qml/qqmlboundsignal.cpp
@@ -72,7 +72,10 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QQmlContextData *ctxt, QObj
setNotifyOnValueChanged(false);
setContext(ctxt);
setScopeObject(scope);
- m_expression = QString::fromUtf8(expression);
+ if (isRewritten)
+ m_expressionUtf8 = expression;
+ else
+ m_expression = QString::fromUtf8(expression);
m_expressionFunctionValid = false;
m_expressionFunctionRewritten = isRewritten;
m_fileName = fileName;
@@ -87,7 +90,10 @@ QQmlBoundSignalExpression::QQmlBoundSignalExpression(QQmlContextData *ctxt, QObj
setNotifyOnValueChanged(false);
setContext(ctxt);
setScopeObject(scope);
- m_expression = expression;
+ if (isRewritten)
+ m_expressionUtf8 = expression.toUtf8();
+ else
+ m_expression = expression;
m_expressionFunctionValid = false;
m_expressionFunctionRewritten = isRewritten;
m_fileName = fileName;
@@ -104,7 +110,7 @@ QQmlBoundSignalExpression::~QQmlBoundSignalExpression()
QString QQmlBoundSignalExpression::expressionIdentifier(QQmlJavaScriptExpression *e)
{
QQmlBoundSignalExpression *This = static_cast<QQmlBoundSignalExpression *>(e);
- return QLatin1Char('"') + This->m_expression + QLatin1Char('"');
+ return This->sourceFile() + QLatin1Char(':') + QString::number(This->lineNumber());
}
void QQmlBoundSignalExpression::expressionChanged(QQmlJavaScriptExpression *)
@@ -112,6 +118,20 @@ void QQmlBoundSignalExpression::expressionChanged(QQmlJavaScriptExpression *)
// bound signals do not notify on change.
}
+QString QQmlBoundSignalExpression::expression() const
+{
+ if (m_expressionFunctionValid) {
+ Q_ASSERT (context() && engine());
+ v8::HandleScope handle_scope;
+ v8::Context::Scope context_scope(QQmlEnginePrivate::get(engine())->v8engine()->context());
+ return QV8Engine::toStringStatic(m_v8function->ToString());
+ } else if (!m_expressionUtf8.isEmpty()) {
+ return QString::fromUtf8(m_expressionUtf8);
+ } else {
+ return m_expression;
+ }
+}
+
// This mirrors code in QQmlExpressionPrivate::value() and v8value().
// Any change made here should be made there and vice versa.
void QQmlBoundSignalExpression::evaluate(QObject *secondaryScope)
@@ -124,18 +144,19 @@ void QQmlBoundSignalExpression::evaluate(QObject *secondaryScope)
v8::HandleScope handle_scope;
v8::Context::Scope context_scope(ep->v8engine()->context());
if (!m_expressionFunctionValid) {
- bool ok = true;
- QString code;
+
if (m_expressionFunctionRewritten) {
- code = m_expression;
+ m_v8function = evalFunction(context(), scopeObject(), m_expressionUtf8, m_fileName, m_line, &m_v8qmlscope);
+ m_expressionUtf8.clear();
} else {
+ bool ok = true;
QQmlRewrite::RewriteSignalHandler rewriteSignalHandler;
- code = rewriteSignalHandler(m_expression, m_functionName, &ok);
+ const QString &code = rewriteSignalHandler(m_expression, QString()/*no name hint available*/, &ok);
+ if (ok)
+ m_v8function = evalFunction(context(), scopeObject(), code, m_fileName, m_line, &m_v8qmlscope);
+ m_expression.clear();
}
- if (ok)
- m_v8function = evalFunction(context(), scopeObject(), code, m_fileName, m_line, &m_v8qmlscope);
-
if (m_v8function.IsEmpty() || m_v8function->IsNull()) {
ep->dereferenceScarceResources();
return; // could not evaluate function. Not valid.