aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-05-03 10:31:05 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-05-10 23:00:40 +0200
commit9da03da2e3fec3cfc9c4e6bfcf7f433845723d65 (patch)
tree086a148ec8128c086a125b3fc842d6032c517c74 /tests
parent1b5463ccfbe3fde74adf8e0651662cad1979c216 (diff)
Apply constant binding removal optimization to QProperty bindings
This applies the logic from 7cb6dce1f3e140ea68d6b05281950f212fc99d38 to non-QQmlAbstractBinding bindings, too. The logic to detect whether a binding has no dependencies has consider the QPropertyBindingPrivate's dependency observer count. In addition, change the existing detection logic to remove properties without a context, too. The original logic probably wanted to guard against accessing binding->context()->unresolvedNames when context was nullptr; however, the check should have tested "context -> unresolvedNames", not "context and unresolvedNames". And after the refactoring which introduced hasUnresolvedNames() as a function, the context check became completely superfluous. Fixes: QTBUG-92996 Change-Id: Ia3bc39e184f431210b3bb2d38154acf820525e98 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/removeQPropertyBindingsWithNoDependencies.qml8
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp8
2 files changed, 16 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/removeQPropertyBindingsWithNoDependencies.qml b/tests/auto/qml/qqmlecmascript/data/removeQPropertyBindingsWithNoDependencies.qml
new file mode 100644
index 0000000000..680e7f4c4e
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/removeQPropertyBindingsWithNoDependencies.qml
@@ -0,0 +1,8 @@
+import Qt.test 1
+
+ClassWithQProperty {
+ id: root
+ function f() {return 42}
+
+ value: f()
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 89e0246623..6f2e241cc1 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -9074,6 +9074,14 @@ void tst_qqmlecmascript::removeBindingsWithNoDependencies()
QVERIFY(!proxy->subBindings());
}
+ {
+ QQmlComponent component(&engine, testFileUrl("removeQPropertyBindingsWithNoDependencies.qml"));
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY2(root, qPrintable(component.errorString()));
+ auto classWithQProperty = qobject_cast<ClassWithQProperty *>(root.get());
+ QVERIFY(!classWithQProperty->bindableValue().hasBinding());
+ QCOMPARE(classWithQProperty->value.value(), 42);
+ }
}
void tst_qqmlecmascript::preserveBindingWithUnresolvedNames()