aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-11-15 15:09:30 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-11-18 11:03:50 +0100
commitbe0b5130df4b88ebbfabf9098b541c27c5d9a5d0 (patch)
tree868e3498b389de1962ee99195c6e1bf3aecf7a81
parent3f170dc2c5d9d0471b38919191e16d3eae38270d (diff)
libshiboken: Streamline newObjectForType
Avoid duplicated wrapper map lookups and repeated calls to BindingManager::instance(). Pick-to: 6.8 Task-number: PYSIDE-2854 Change-Id: I10445102d9cb3c2c8b9159b715b6e8cca49971a8 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken6/libshiboken/basewrapper.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index b1f7bea9b..ee5c7cc69 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -1530,10 +1530,9 @@ PyObject *newObjectForType(PyTypeObject *instanceType, void *cptr, bool hasOwner
bool shouldRegister = true;
SbkObject *self = nullptr;
+ auto &bindingManager = BindingManager::instance();
// Some logic to ensure that colocated child field does not overwrite the parent
- if (BindingManager::instance().hasWrapper(cptr)) {
- SbkObject *existingWrapper = BindingManager::instance().retrieveWrapper(cptr);
-
+ if (SbkObject *existingWrapper = bindingManager.retrieveWrapper(cptr)) {
self = findColocatedChild(existingWrapper, instanceType);
if (self) {
// Wrapper already registered for cptr.
@@ -1544,7 +1543,7 @@ PyObject *newObjectForType(PyTypeObject *instanceType, void *cptr, bool hasOwner
(!(Shiboken::Object::hasCppWrapper(existingWrapper) ||
Shiboken::Object::hasOwnership(existingWrapper)))) {
// Old wrapper is likely junk, since we have ownership and it doesn't.
- BindingManager::instance().releaseWrapper(existingWrapper);
+ bindingManager.releaseWrapper(existingWrapper);
} else {
// Old wrapper may be junk caused by some bug in identifying object deletion
// but it may not be junk when a colocated field is accessed for an
@@ -1559,9 +1558,8 @@ PyObject *newObjectForType(PyTypeObject *instanceType, void *cptr, bool hasOwner
self->d->cptr[0] = cptr;
self->d->hasOwnership = hasOwnership;
self->d->validCppObject = 1;
- if (shouldRegister) {
- BindingManager::instance().registerWrapper(self, cptr);
- }
+ if (shouldRegister)
+ bindingManager.registerWrapper(self, cptr);
} else {
Py_IncRef(reinterpret_cast<PyObject *>(self));
}