Avoid redundant lookup

PR #20890.
This commit is contained in:
Chocobo1 2024-05-30 19:35:58 +08:00 committed by GitHub
parent 4155d4660f
commit 41d8f473b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -411,7 +411,7 @@ void PeerListWidget::loadPeers(const BitTorrent::Torrent *torrent)
return;
// 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_I2PPeerItems.clear();
@ -466,10 +466,14 @@ void PeerListWidget::loadPeers(const BitTorrent::Torrent *torrent)
{
QStandardItem *item = m_peerItems.take(peerEndpoint);
QSet<QStandardItem *> &items = m_itemsByIP[peerEndpoint.address.ip];
items.remove(item);
if (items.isEmpty())
m_itemsByIP.remove(peerEndpoint.address.ip);
const auto items = m_itemsByIP.find(peerEndpoint.address.ip);
Q_ASSERT(items != m_itemsByIP.end());
if (items == m_itemsByIP.end()) [[unlikely]]
continue;
items->remove(item);
if (items->isEmpty())
m_itemsByIP.erase(items);
m_listModel->removeRow(item->row());
}