diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-07-08 10:57:21 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-07-10 15:07:07 +0200 |
commit | be1ce6b26909256e62c2b39e4de9f8f79d070937 (patch) | |
tree | 56ae09231c362010b17df127c4d7c17ab4943f30 /tests/auto | |
parent | 0d1208f0f08727c55de9eed8e0ceef092080b927 (diff) |
Separate the error case when evaluating bindings
There's no point in returning a usually empty error when
evaluating bindings, adding overhead to the regular code
path.
Instead, the error can be set on the currently evaluating
binding if required. This streamlines the functor used to
wrap the binding and should thus expand to less code and
execute faster in the regular case.
To achieve this, expose a pointer to the currently evaluating
binding in the private API (as QtQml needs it to be able to
report errors).
The error case now requires one additional TLS lookup, but
we don't really care about performance in that case anyway.
Change-Id: Iecb450e765244930a41d813fcf8eb4013957a6a3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 50a8d51a46..f14ba78b02 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -505,9 +505,10 @@ void tst_QProperty::bindingSourceLocation() void tst_QProperty::bindingError() { - QProperty<int> prop = Qt::makePropertyBinding([]() -> std::variant<int, QPropertyBindingError> { + QProperty<int> prop = Qt::makePropertyBinding([]() -> int { QPropertyBindingError error(QPropertyBindingError::UnknownError, QLatin1String("my error")); - return error; + QPropertyBindingPrivate::currentlyEvaluatingBinding()->setError(std::move(error)); + return 0; }); QCOMPARE(prop.value(), 0); QCOMPARE(prop.binding().error().description(), QString("my error")); @@ -621,20 +622,18 @@ void tst_QProperty::genericPropertyBinding() { QUntypedPropertyBinding doubleBinding(QMetaType::fromType<double>(), - [](const QMetaType &, void *) -> QUntypedPropertyBinding::BindingEvaluationResult { + [](const QMetaType &, void *) -> void { Q_ASSERT(false); - return QPropertyBindingError::NoError; }, QPropertyBindingSourceLocation()); QVERIFY(!property.setBinding(doubleBinding)); } QUntypedPropertyBinding intBinding(QMetaType::fromType<int>(), - [](const QMetaType &metaType, void *dataPtr) -> QUntypedPropertyBinding::BindingEvaluationResult { + [](const QMetaType &metaType, void *dataPtr) -> void { Q_ASSERT(metaType.id() == qMetaTypeId<int>()); int *intPtr = reinterpret_cast<int*>(dataPtr); *intPtr = 100; - return QPropertyBindingError::NoError; }, QPropertyBindingSourceLocation()); QVERIFY(property.setBinding(intBinding)); @@ -649,10 +648,9 @@ void tst_QProperty::genericPropertyBindingBool() QVERIFY(!property.value()); QUntypedPropertyBinding boolBinding(QMetaType::fromType<bool>(), - [](const QMetaType &, void *dataPtr) -> QUntypedPropertyBinding::BindingEvaluationResult { + [](const QMetaType &, void *dataPtr) -> void { auto boolPtr = reinterpret_cast<bool *>(dataPtr); *boolPtr = true; - return {}; }, QPropertyBindingSourceLocation()); QVERIFY(property.setBinding(boolBinding)); |