Avoid redundant lookup

PR #20890.
This commit is contained in:
Chocobo1 2024-05-30 19:35:58 +08:00 committed by sledgehammer999
parent c44e300507
commit 8bad80bcdd
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2

View file

@ -411,7 +411,7 @@ void PeerListWidget::loadPeers(const BitTorrent::Torrent *torrent)
return; return;
// Remove I2P peers since they will be completely reloaded. // Remove I2P peers since they will be completely reloaded.
for (QStandardItem *item : asConst(m_I2PPeerItems)) for (const QStandardItem *item : asConst(m_I2PPeerItems))
m_listModel->removeRow(item->row()); m_listModel->removeRow(item->row());
m_I2PPeerItems.clear(); m_I2PPeerItems.clear();
@ -466,10 +466,14 @@ void PeerListWidget::loadPeers(const BitTorrent::Torrent *torrent)
{ {
QStandardItem *item = m_peerItems.take(peerEndpoint); QStandardItem *item = m_peerItems.take(peerEndpoint);
QSet<QStandardItem *> &items = m_itemsByIP[peerEndpoint.address.ip]; const auto items = m_itemsByIP.find(peerEndpoint.address.ip);
items.remove(item); Q_ASSERT(items != m_itemsByIP.end());
if (items.isEmpty()) if (items == m_itemsByIP.end()) [[unlikely]]
m_itemsByIP.remove(peerEndpoint.address.ip); continue;
items->remove(item);
if (items->isEmpty())
m_itemsByIP.erase(items);
m_listModel->removeRow(item->row()); m_listModel->removeRow(item->row());
} }