|
46 | 46 | #include <QMetaObject> |
47 | 47 | #include <QMetaMethod> |
48 | 48 |
|
| 49 | +#include <algorithm> |
| 50 | + |
49 | 51 | // use -2 to signal that the variable is uninitialized |
50 | 52 | int PythonQtSignalReceiver::_destroyedSignal1Id = -2; |
51 | 53 | int PythonQtSignalReceiver::_destroyedSignal2Id = -2; |
@@ -306,18 +308,18 @@ int PythonQtSignalReceiver::qt_metacall(QMetaObject::Call c, int id, void** argu |
306 | 308 | // while _targets is modified because a connect/disconnect is done from Python code (which would also hold the GIL) |
307 | 309 | PYTHONQT_GIL_SCOPE |
308 | 310 | bool shouldDelete = false; |
309 | | - for (const PythonQtSignalTarget& t : qAsConst(_targets)) { |
310 | | - if (t.slotId() == id) { |
311 | | - const int sigId = t.signalId(); |
312 | | - t.call(arguments); |
313 | | - // if the signal is the last destroyed signal, we delete ourselves |
314 | | - if ((sigId == _destroyedSignal1Id) || (sigId == _destroyedSignal2Id)) { |
315 | | - _destroyedSignalCount--; |
316 | | - if (_destroyedSignalCount == 0) { |
317 | | - shouldDelete = true; |
318 | | - } |
| 311 | + auto it = std::lower_bound(_targets.begin(), _targets.end(), id, |
| 312 | + [](const PythonQtSignalTarget& t, int id) -> bool { return t.slotId() < id; }); |
| 313 | + if (it != _targets.end() && it->slotId() == id) { |
| 314 | + const PythonQtSignalTarget& t = *it; |
| 315 | + const int sigId = t.signalId(); |
| 316 | + t.call(arguments); |
| 317 | + // if the signal is the last destroyed signal, we delete ourselves |
| 318 | + if ((sigId == _destroyedSignal1Id) || (sigId == _destroyedSignal2Id)) { |
| 319 | + _destroyedSignalCount--; |
| 320 | + if (_destroyedSignalCount == 0) { |
| 321 | + shouldDelete = true; |
319 | 322 | } |
320 | | - break; |
321 | 323 | } |
322 | 324 | } |
323 | 325 | if (shouldDelete) { |
|
0 commit comments