diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-11-25 13:06:37 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-11-30 23:02:30 +0000 |
commit | e095bebaf5f3a437c72f02a5d8c63ae88e15a394 (patch) | |
tree | 720a30b06b33599e2a4eaae030827cecbf386728 /src/corelib/kernel/qproperty.cpp | |
parent | ba0e0129023a4454ddb03f6375dbbe5eb2b8dabb (diff) |
Smaller cleanup in QBindingStorage
Unify code paths and avoid excessive code generation.
Change-Id: I4a54234dd322bba380cc45d4f9c97d97a0c93303
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 65759c9867321d978c1f98f5cf66bef11c8f5c15)
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/corelib/kernel/qproperty.cpp')
-rw-r--r-- | src/corelib/kernel/qproperty.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index 01204199cb..a93fcdad03 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -1438,10 +1438,13 @@ struct QBindingStoragePrivate } return nullptr; } - QPropertyBindingData *getAndCreate(QUntypedPropertyData *data) + QPropertyBindingData *get(QUntypedPropertyData *data, bool create) { - if (!d) + if (!d) { + if (!create) + return nullptr; reallocate(8); + } else if (d->used*2 >= d->size) reallocate(d->size*2); Q_ASSERT(d->size && (d->size & (d->size - 1)) == 0); // size is a power of two @@ -1454,6 +1457,8 @@ struct QBindingStoragePrivate if (index == d->size) index = 0; } + if (!create) + return nullptr; ++d->used; new (p + index) Pair{data, QPropertyBindingData()}; return &p[index].bindingData; @@ -1499,14 +1504,12 @@ void QBindingStorage::maybeUpdateBindingAndRegister_helper(const QUntypedPropert { Q_ASSERT(bindingStatus); QUntypedPropertyData *dd = const_cast<QUntypedPropertyData *>(data); - auto storage = bindingStatus->currentlyEvaluatingBinding ? - QBindingStoragePrivate(d).getAndCreate(dd) : - (d ? QBindingStoragePrivate(d).get(dd) : nullptr); + auto storage = QBindingStoragePrivate(d).get(dd, /*create=*/ bindingStatus->currentlyEvaluatingBinding != nullptr); if (!storage) return; if (auto *binding = storage->binding()) - binding->evaluateIfDirtyAndReturnTrueIfValueChanged(const_cast<QUntypedPropertyData *>(data)); - storage->registerWithCurrentlyEvaluatingBinding(); + binding->evaluateIfDirtyAndReturnTrueIfValueChanged(const_cast<QUntypedPropertyData *>(data), bindingStatus); + storage->registerWithCurrentlyEvaluatingBinding(bindingStatus->currentlyEvaluatingBinding); } QPropertyBindingData *QBindingStorage::bindingData_helper(const QUntypedPropertyData *data) const @@ -1516,10 +1519,7 @@ QPropertyBindingData *QBindingStorage::bindingData_helper(const QUntypedProperty QPropertyBindingData *QBindingStorage::bindingData_helper(QUntypedPropertyData *data, bool create) { - auto storage = create ? - QBindingStoragePrivate(d).getAndCreate(data) : - QBindingStoragePrivate(d).get(data); - return storage; + return QBindingStoragePrivate(d).get(data, create); } QT_END_NAMESPACE |