From a357e490edcbcc1fda664a64ee8c6af626225e06 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 6 Jun 2018 20:35:00 -0400 Subject: [PATCH] minor code refactor, more use of auto --- include/libtorrent/disk_io_job.hpp | 2 -- src/disk_io_thread.cpp | 4 ++-- src/disk_job_fence.cpp | 1 - src/disk_job_pool.cpp | 2 +- src/parse_url.cpp | 12 +++++------- src/resolver.cpp | 14 +++++--------- 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/include/libtorrent/disk_io_job.hpp b/include/libtorrent/disk_io_job.hpp index 82345a33c..792cb8738 100644 --- a/include/libtorrent/disk_io_job.hpp +++ b/include/libtorrent/disk_io_job.hpp @@ -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" diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 42d8ef60c..bb6e1180a 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -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(); diff --git a/src/disk_job_fence.cpp b/src/disk_job_fence.cpp index 21927779e..0ed093f4d 100644 --- a/src/disk_job_fence.cpp +++ b/src/disk_job_fence.cpp @@ -232,4 +232,3 @@ namespace libtorrent { namespace aux { } }} - diff --git a/src/disk_job_pool.cpp b/src/disk_job_pool.cpp index 49e23dfbf..4a9cb4d1c 100644 --- a/src/disk_job_pool.cpp +++ b/src/disk_job_pool.cpp @@ -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; diff --git a/src/parse_url.cpp b/src/parse_url.cpp index 8855f9d1d..7efd77d6d 100644 --- a/src/parse_url.cpp +++ b/src/parse_url.cpp @@ -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 "://" diff --git a/src/resolver.cpp b/src/resolver.cpp index 57e73faa4..c6281b4c2 100644 --- a/src/resolver.cpp +++ b/src/resolver.cpp @@ -54,14 +54,12 @@ namespace libtorrent { COMPLETE_ASYNC("resolver::on_lookup"); if (ec) { - std::vector
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
addresses; - addresses.push_back(ip); - m_ios.post(std::bind(h, ec, addresses)); + m_ios.post(std::bind(h, ec, std::vector
{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
())); + , std::vector
{})); 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;