aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlrewrite_p.h
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2012-05-30 10:16:13 +0100
committerQt by Nokia <qt-info@nokia.com>2012-08-29 06:38:54 +0200
commit04774bb14c81688f86a2b31b8624bde8ebf59062 (patch)
tree9d04d18712988caca2a3f193feb94cfaa35b47bb /src/qml/qml/qqmlrewrite_p.h
parentd65fb68de12b6d811f7b94ba3209847f73ca94cc (diff)
Evaluate bindings more intelligently during construction
Instead of just evaluating bindings in a fixed order, and possibly having to evaluate a single binding multiple times, prior to reading a property, we check if there are any bindings "pending" on it and evaluate them then. A pending binding is one that has been assigned to the property, but not yet evaluated. To minimize side effects we only do this for "safe" bindings. A safe binding is one that has no side effects, which we currently define as not calling functions or otherwise assigning values during its evaluation. This isn't an entirely foolproof way to ensure that the evaluation has no side effects, but it should be good enough. Change-Id: I98aa76a95719e5d182e8941738d64f8d409f404a Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmlrewrite_p.h')
-rw-r--r--src/qml/qml/qqmlrewrite_p.h47
1 files changed, 19 insertions, 28 deletions
diff --git a/src/qml/qml/qqmlrewrite_p.h b/src/qml/qml/qqmlrewrite_p.h
index 26027a0ded..519846c41e 100644
--- a/src/qml/qml/qqmlrewrite_p.h
+++ b/src/qml/qml/qqmlrewrite_p.h
@@ -67,13 +67,25 @@ using namespace QQmlJS;
class SharedBindingTester : protected AST::Visitor
{
bool _sharable;
+ bool _safe;
public:
- bool isSharable(const QString &code);
- bool isSharable(AST::Node *Node);
+ SharedBindingTester();
+
+ bool isSharable() const { return _sharable; }
+ bool isSafe() const { return isSharable() && _safe; }
+
+ void parse(const QString &code);
+ void parse(AST::Node *Node);
- inline virtual bool visit(AST::FunctionDeclaration *);
- inline virtual bool visit(AST::FunctionExpression *);
- inline virtual bool visit(AST::IdentifierExpression *);
+ virtual bool visit(AST::FunctionDeclaration *);
+ virtual bool visit(AST::FunctionExpression *);
+ virtual bool visit(AST::IdentifierExpression *);
+ virtual bool visit(AST::CallExpression *);
+ virtual bool visit(AST::PostDecrementExpression *);
+ virtual bool visit(AST::PostIncrementExpression *);
+ virtual bool visit(AST::PreDecrementExpression *);
+ virtual bool visit(AST::PreIncrementExpression *);
+ virtual bool visit(AST::BinaryExpression *);
};
class RewriteBinding: protected AST::Visitor
@@ -84,8 +96,8 @@ class RewriteBinding: protected AST::Visitor
const QString *_code;
public:
- QString operator()(const QString &code, bool *ok = 0, bool *sharable = 0);
- QString operator()(QQmlJS::AST::Node *node, const QString &code, bool *sharable = 0);
+ QString operator()(const QString &code, bool *ok = 0, bool *sharable = 0, bool *safe = 0);
+ QString operator()(QQmlJS::AST::Node *node, const QString &code, bool *sharable = 0, bool *safe = 0);
//name of the function: used for the debugger
void setName(const QString &name) { _name = name; }
@@ -177,27 +189,6 @@ private:
QString _error;
};
-bool SharedBindingTester::visit(AST::FunctionDeclaration *)
-{
- _sharable = false;
- return false;
-}
-
-bool SharedBindingTester::visit(AST::FunctionExpression *)
-{
- _sharable = false;
- return false;
-}
-
-bool SharedBindingTester::visit(AST::IdentifierExpression *e)
-{
- static const QString evalString = QStringLiteral("eval");
- if (e->name == evalString)
- _sharable = false;
-
- return false; // IdentifierExpression is a leaf node anyway
-}
-
} // namespace QQmlRewrite
QT_END_NAMESPACE