mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-17 22:18:05 -06:00
Don't create temporary containers just to iterate over them
Stops temporary containers being created needlessly due to API misuse. For example, it’s common for developers to assume QHash::values() and QHash::keys() are free and abuse them, failing to realize their implementation internally actually iterates the whole container, allocates memory, and fills a new QList. Added a removeIf generic algorithm, similar to std ones. We can't use std algorithms with Qt dictionaries because Qt iterators have different behavior from the std ones. Found using clazy.
This commit is contained in:
committed by
Vladimir Golovnev (Glassez)
parent
e22946ef61
commit
ac42ccb5e4
@@ -121,8 +121,10 @@ void PortForwarder::start()
|
||||
settingsPack.set_bool(libt::settings_pack::enable_natpmp, true);
|
||||
m_provider->apply_settings(settingsPack);
|
||||
#endif
|
||||
foreach (quint16 port, m_mappedPorts.keys())
|
||||
m_mappedPorts[port] = m_provider->add_port_mapping(libt::session::tcp, port, port);
|
||||
for (auto i = m_mappedPorts.begin(); i != m_mappedPorts.end(); ++i) {
|
||||
// quint16 port = i.key();
|
||||
i.value() = m_provider->add_port_mapping(libt::session::tcp, i.key(), i.key());
|
||||
}
|
||||
m_active = true;
|
||||
Logger::instance()->addMessage(tr("UPnP / NAT-PMP support [ON]"), Log::INFO);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user