more use of emplace_back and minor code simplification

This commit is contained in:
Alden Torres 2017-08-16 17:21:11 -04:00 committed by Arvid Norberg
parent 05b5b4ef4d
commit 070066e892
3 changed files with 6 additions and 8 deletions

View File

@ -173,9 +173,7 @@ namespace {
int file_storage::get_or_add_path(string_view const path)
{
// do we already have this path in the path list?
auto p = std::find_if(m_paths.rbegin(), m_paths.rend()
, [&] (std::string const& str)
{ return str == path; });
auto const p = std::find(m_paths.rbegin(), m_paths.rend(), path);
if (p == m_paths.rend())
{

View File

@ -390,7 +390,7 @@ void http_connection::start(std::string const& hostname, int port
{
m_hostname = hostname;
m_port = std::uint16_t(port);
m_endpoints.push_back({address(), m_port});
m_endpoints.emplace_back(address(), m_port);
connect();
}
else
@ -515,7 +515,7 @@ void http_connection::on_resolve(error_code const& e
TORRENT_ASSERT(!addresses.empty());
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_endpoints.empty())

View File

@ -217,7 +217,7 @@ namespace libtorrent {
if (addr.is_v6() && addr.to_v6().scope_id() != scope)
continue;
#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())
@ -261,7 +261,7 @@ namespace libtorrent {
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());
if (bind_interface() != address_v4::any())
@ -668,7 +668,7 @@ namespace libtorrent {
for (int i = 0; i < num_peers; ++i)
{
ipv4_peer_entry e;
memcpy(e.ip.data(), buf.data(), 4);
std::memcpy(e.ip.data(), buf.data(), 4);
buf = buf.subspan(4);
e.port = aux::read_uint16(buf);
resp.peers4.push_back(e);