aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/libpyside
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2018-09-12 10:47:02 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2018-09-12 11:24:12 +0000
commit248ab8c8740de3e0adb203dd207862b35cfc69fe (patch)
treebeb15a490d986a515cae72c34e034267b21bc03d /sources/pyside2/libpyside
parent0187d2b17dd5d35d645b70a2cf08c7100c0d6a14 (diff)
libpyside: Fix contains()/value() antipattern
Use iterators instead, avoiding repeated lookups of hashes and maps. Change-Id: I3b430bdf0ceef1980baeca45849880d35538e89b Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/pyside2/libpyside')
-rw-r--r--sources/pyside2/libpyside/globalreceiver.cpp18
-rw-r--r--sources/pyside2/libpyside/globalreceiverv2.cpp5
-rw-r--r--sources/pyside2/libpyside/signalmanager.cpp.in8
3 files changed, 18 insertions, 13 deletions
diff --git a/sources/pyside2/libpyside/globalreceiver.cpp b/sources/pyside2/libpyside/globalreceiver.cpp
index 9f0eea4f8..78382f5a4 100644
--- a/sources/pyside2/libpyside/globalreceiver.cpp
+++ b/sources/pyside2/libpyside/globalreceiver.cpp
@@ -207,8 +207,9 @@ GlobalReceiver::~GlobalReceiver()
void GlobalReceiver::connectNotify(QObject* source, int slotId)
{
- if (m_slotReceivers.contains(slotId)) {
- DynamicSlotData* data = m_slotReceivers[slotId];
+ const auto it = m_slotReceivers.constFind(slotId);
+ if (it != m_slotReceivers.cend()) {
+ DynamicSlotData* data = it.value();
if (!data->hasRefTo(source))
QObject::connect(source, SIGNAL(destroyed(QObject*)), this, "1" RECEIVER_DESTROYED_SLOT_NAME);
data->addRef(source);
@@ -217,8 +218,9 @@ void GlobalReceiver::connectNotify(QObject* source, int slotId)
void GlobalReceiver::disconnectNotify(QObject* source, int slotId)
{
- if (m_slotReceivers.contains(slotId)) {
- DynamicSlotData *data = m_slotReceivers[slotId];
+ const auto it = m_slotReceivers.constFind(slotId);
+ if (it != m_slotReceivers.cend()) {
+ DynamicSlotData* data = it.value();
data->decRef(source);
if (data->refCount() == 0)
removeSlot(slotId);
@@ -237,7 +239,7 @@ int GlobalReceiver::addSlot(const char* slot, PyObject* callback)
{
int slotId = m_metaObject.addSlot(slot);
if (!m_slotReceivers.contains(slotId))
- m_slotReceivers[slotId] = new DynamicSlotData(slotId, callback, this);
+ m_slotReceivers.insert(slotId, new DynamicSlotData(slotId, callback, this));
bool isShortCircuit = true;
for (int i = 0; slot[i]; ++i) {
@@ -256,8 +258,10 @@ int GlobalReceiver::addSlot(const char* slot, PyObject* callback)
void GlobalReceiver::removeSlot(int slotId)
{
- if (m_slotReceivers.contains(slotId)) {
- delete m_slotReceivers.take(slotId);
+ auto it = m_slotReceivers.find(slotId);
+ if (it != m_slotReceivers.end()) {
+ delete it.value();
+ m_slotReceivers.erase(it);
m_metaObject.removeSlot(slotId);
m_shortCircuitSlots.remove(slotId);
}
diff --git a/sources/pyside2/libpyside/globalreceiverv2.cpp b/sources/pyside2/libpyside/globalreceiverv2.cpp
index 5b8785563..0c30f2c5f 100644
--- a/sources/pyside2/libpyside/globalreceiverv2.cpp
+++ b/sources/pyside2/libpyside/globalreceiverv2.cpp
@@ -155,9 +155,8 @@ PyObject* DynamicSlotDataV2::callback()
int DynamicSlotDataV2::id(const char* signature) const
{
- if (m_signatures.contains(signature))
- return m_signatures[signature];
- return -1;
+ const auto it = m_signatures.constFind(signature);
+ return it != m_signatures.cend() ? it.value() : -1;
}
int DynamicSlotDataV2::addSlot(const char* signature)
diff --git a/sources/pyside2/libpyside/signalmanager.cpp.in b/sources/pyside2/libpyside/signalmanager.cpp.in
index 6ed2c3a97..9b5c5eb9a 100644
--- a/sources/pyside2/libpyside/signalmanager.cpp.in
+++ b/sources/pyside2/libpyside/signalmanager.cpp.in
@@ -338,14 +338,16 @@ QObject* SignalManager::globalReceiver(QObject *sender, PyObject *callback)
SharedMap globalReceivers = m_d->m_globalReceivers;
QByteArray hash = GlobalReceiverV2::hash(callback);
GlobalReceiverV2* gr = 0;
- if (!globalReceivers->contains(hash)) {
- gr = (*globalReceivers)[hash] = new GlobalReceiverV2(callback, globalReceivers);
+ auto it = globalReceivers->find(hash);
+ if (it == globalReceivers->end()) {
+ gr = new GlobalReceiverV2(callback, globalReceivers);
+ globalReceivers->insert(hash, gr);
if (sender) {
gr->incRef(sender); // create a link reference
gr->decRef(); // remove extra reference
}
} else {
- gr = (*globalReceivers)[hash];
+ gr = it.value();
if (sender)
gr->incRef(sender);
}