diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-20 10:26:24 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-01-21 17:00:29 +0100 |
commit | 3861ec735e669aa43c2a0177f948b84d8cac0797 (patch) | |
tree | e3e59b7dc9c043fda925c7b10692e9b825b9d2d1 /tests/auto | |
parent | 150660887f9cb402e16e351252a6ccdbee235ad9 (diff) |
QProperty: Add private isAnyBindingEvaluating function
To optimize certain operations, it can be useful to know whether we are
currently evaluating a binding. For instance, we have properties whose
storage is only alloctaed on-demand when they are set. However, we would
also allocate them if they are used in a binding context, as we would
otherwise not properly track the dependency. Using
isAnyBindingEvaluating in the getter, we can detect this
situation, and avoid the allocation if it returns false.
This API is private for now, as it exposes some internals of the
property system and should be used with care. As it needs to access the
TLS variable, it also has a non-negligible cost.
Change-Id: I373aabee644fe7020b2ffba7d6a0ad9a1e1b4ec0
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 7de6458406..3b656dae25 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -1140,6 +1140,15 @@ void tst_QProperty::testNewStuff() QCOMPARE(object.bindableFoo().value(), 111); object.bindableFoo().setValue(24); QCOMPARE(object.foo(), 24); + + auto isCurrentlyEvaluatingBinding = []() { + return QtPrivate::isAnyBindingEvaluating(); + }; + QVERIFY(!isCurrentlyEvaluatingBinding()); + QProperty<bool> evaluationDetector {false}; + evaluationDetector.setBinding(isCurrentlyEvaluatingBinding); + QVERIFY(evaluationDetector.value()); + QVERIFY(!isCurrentlyEvaluatingBinding()); } void tst_QProperty::qobjectObservers() |