minor code refactor, more use of auto

This commit is contained in:
Alden Torres 2018-06-06 20:35:00 -04:00 committed by Arvid Norberg
parent e88339378c
commit a357e490ed
6 changed files with 13 additions and 22 deletions

View File

@ -36,8 +36,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/fwd.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/tailqueue.hpp"
#include "libtorrent/peer_request.hpp"
#include "libtorrent/aux_/block_cache_reference.hpp"
#include "libtorrent/sha1_hash.hpp"
#include "libtorrent/disk_interface.hpp"
#include "libtorrent/aux_/vector.hpp"

View File

@ -169,9 +169,9 @@ namespace libtorrent {
{
explicit scoped_unlocker_impl(Lock& l) : m_lock(&l) { m_lock->unlock(); }
~scoped_unlocker_impl() { if (m_lock) m_lock->lock(); }
scoped_unlocker_impl(scoped_unlocker_impl&& rhs) : m_lock(rhs.m_lock)
scoped_unlocker_impl(scoped_unlocker_impl&& rhs) noexcept : m_lock(rhs.m_lock)
{ rhs.m_lock = nullptr; }
scoped_unlocker_impl& operator=(scoped_unlocker_impl&& rhs)
scoped_unlocker_impl& operator=(scoped_unlocker_impl&& rhs) noexcept
{
if (&rhs == this) return *this;
if (m_lock) m_lock->lock();

View File

@ -232,4 +232,3 @@ namespace libtorrent { namespace aux {
}
}}

View File

@ -85,7 +85,7 @@ namespace libtorrent {
m_job_pool.free(j);
}
void disk_job_pool::free_jobs(disk_io_job** j, int num)
void disk_job_pool::free_jobs(disk_io_job** j, int const num)
{
if (num == 0) return;

View File

@ -51,12 +51,11 @@ namespace libtorrent {
std::string::iterator port_pos;
// PARSE URL
std::string::iterator start = url.begin();
auto start = url.begin();
// remove white spaces in front of the url
while (start != url.end() && is_space(*start))
++start;
std::string::iterator end
= std::find(url.begin(), url.end(), ':');
auto end = std::find(url.begin(), url.end(), ':');
protocol.assign(start, end);
if (end == url.end())
@ -116,7 +115,7 @@ namespace libtorrent {
if (port_pos < end)
{
++port_pos;
for (std::string::iterator i = port_pos; i < end; ++i)
for (auto i = port_pos; i < end; ++i)
{
if (is_digit(*i)) continue;
ec = errors::invalid_port;
@ -142,14 +141,13 @@ exit:
std::string path;
// PARSE URL
std::string::iterator pos
= std::find(url.begin(), url.end(), ':');
auto pos = std::find(url.begin(), url.end(), ':');
if (pos == url.end() || url.end() - pos < 3
|| *(pos + 1) != '/' || *(pos + 2) != '/')
{
ec = errors::unsupported_url_protocol;
return std::make_tuple(url, path);
return std::make_tuple(std::move(url), std::move(path));
}
pos += 3; // skip "://"

View File

@ -54,14 +54,12 @@ namespace libtorrent {
COMPLETE_ASYNC("resolver::on_lookup");
if (ec)
{
std::vector<address> empty;
h(ec, empty);
h(ec, {});
return;
}
dns_cache_entry& ce = m_cache[hostname];
time_point now = aux::time_now();
ce.last_seen = now;
ce.last_seen = aux::time_now();
ce.addresses.clear();
while (i != tcp::resolver::iterator())
{
@ -96,9 +94,7 @@ namespace libtorrent {
address const ip = make_address(host, ec);
if (!ec)
{
std::vector<address> addresses;
addresses.push_back(ip);
m_ios.post(std::bind(h, ec, addresses));
m_ios.post(std::bind(h, ec, std::vector<address>{ip}));
return;
}
ec.clear();
@ -119,7 +115,7 @@ namespace libtorrent {
{
// we did not find a cache entry, fail the lookup
m_ios.post(std::bind(h, boost::asio::error::host_not_found
, std::vector<address>()));
, std::vector<address>{}));
return;
}
@ -145,7 +141,7 @@ namespace libtorrent {
m_resolver.cancel();
}
void resolver::set_cache_timeout(seconds timeout)
void resolver::set_cache_timeout(seconds const timeout)
{
if (timeout >= seconds(0))
m_timeout = timeout;