more use of emplace_back and minor code simplification
This commit is contained in:
parent
05b5b4ef4d
commit
070066e892
|
@ -173,9 +173,7 @@ namespace {
|
||||||
int file_storage::get_or_add_path(string_view const path)
|
int file_storage::get_or_add_path(string_view const path)
|
||||||
{
|
{
|
||||||
// do we already have this path in the path list?
|
// do we already have this path in the path list?
|
||||||
auto p = std::find_if(m_paths.rbegin(), m_paths.rend()
|
auto const p = std::find(m_paths.rbegin(), m_paths.rend(), path);
|
||||||
, [&] (std::string const& str)
|
|
||||||
{ return str == path; });
|
|
||||||
|
|
||||||
if (p == m_paths.rend())
|
if (p == m_paths.rend())
|
||||||
{
|
{
|
||||||
|
|
|
@ -390,7 +390,7 @@ void http_connection::start(std::string const& hostname, int port
|
||||||
{
|
{
|
||||||
m_hostname = hostname;
|
m_hostname = hostname;
|
||||||
m_port = std::uint16_t(port);
|
m_port = std::uint16_t(port);
|
||||||
m_endpoints.push_back({address(), m_port});
|
m_endpoints.emplace_back(address(), m_port);
|
||||||
connect();
|
connect();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -515,7 +515,7 @@ void http_connection::on_resolve(error_code const& e
|
||||||
TORRENT_ASSERT(!addresses.empty());
|
TORRENT_ASSERT(!addresses.empty());
|
||||||
|
|
||||||
for (auto const& addr : addresses)
|
for (auto const& addr : addresses)
|
||||||
m_endpoints.push_back({addr, m_port});
|
m_endpoints.emplace_back(addr, m_port);
|
||||||
|
|
||||||
if (m_filter_handler) m_filter_handler(*this, m_endpoints);
|
if (m_filter_handler) m_filter_handler(*this, m_endpoints);
|
||||||
if (m_endpoints.empty())
|
if (m_endpoints.empty())
|
||||||
|
|
|
@ -217,7 +217,7 @@ namespace libtorrent {
|
||||||
if (addr.is_v6() && addr.to_v6().scope_id() != scope)
|
if (addr.is_v6() && addr.to_v6().scope_id() != scope)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
m_endpoints.push_back(tcp::endpoint(addr, std::uint16_t(port)));
|
m_endpoints.emplace_back(addr, std::uint16_t(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_endpoints.empty())
|
if (m_endpoints.empty())
|
||||||
|
@ -261,7 +261,7 @@ namespace libtorrent {
|
||||||
|
|
||||||
udp::endpoint udp_tracker_connection::pick_target_endpoint() const
|
udp::endpoint udp_tracker_connection::pick_target_endpoint() const
|
||||||
{
|
{
|
||||||
std::vector<tcp::endpoint>::const_iterator iter = m_endpoints.begin();
|
auto iter = m_endpoints.begin();
|
||||||
udp::endpoint target = udp::endpoint(iter->address(), iter->port());
|
udp::endpoint target = udp::endpoint(iter->address(), iter->port());
|
||||||
|
|
||||||
if (bind_interface() != address_v4::any())
|
if (bind_interface() != address_v4::any())
|
||||||
|
@ -668,7 +668,7 @@ namespace libtorrent {
|
||||||
for (int i = 0; i < num_peers; ++i)
|
for (int i = 0; i < num_peers; ++i)
|
||||||
{
|
{
|
||||||
ipv4_peer_entry e;
|
ipv4_peer_entry e;
|
||||||
memcpy(e.ip.data(), buf.data(), 4);
|
std::memcpy(e.ip.data(), buf.data(), 4);
|
||||||
buf = buf.subspan(4);
|
buf = buf.subspan(4);
|
||||||
e.port = aux::read_uint16(buf);
|
e.port = aux::read_uint16(buf);
|
||||||
resp.peers4.push_back(e);
|
resp.peers4.push_back(e);
|
||||||
|
|
Loading…
Reference in New Issue