From 0132221031d1316af2c44b9bdfbc13ba608cc264 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Tue, 4 Apr 2017 16:42:37 -0400 Subject: [PATCH] minor code cleanup, std:: prefix, consts, typos --- include/libtorrent/aux_/deferred_handler.hpp | 1 - include/libtorrent/bencode.hpp | 2 +- include/libtorrent/http_parser.hpp | 3 +-- src/http_connection.cpp | 4 ++-- src/http_parser.cpp | 10 +++++----- src/http_seed_connection.cpp | 4 ++-- src/torrent.cpp | 2 +- src/utp_stream.cpp | 2 +- test/test_http_connection.cpp | 5 ++--- test/test_socket_io.cpp | 2 +- 10 files changed, 16 insertions(+), 19 deletions(-) diff --git a/include/libtorrent/aux_/deferred_handler.hpp b/include/libtorrent/aux_/deferred_handler.hpp index a6f635e42..b8f5bec3d 100644 --- a/include/libtorrent/aux_/deferred_handler.hpp +++ b/include/libtorrent/aux_/deferred_handler.hpp @@ -71,4 +71,3 @@ private: }} #endif - diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index 3e6885673..814446745 100644 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -242,7 +242,7 @@ namespace libtorrent ++in; // 'e' ret = entry(entry::int_t); char* end_pointer; - ret.integer() = strtoll(val.c_str(), &end_pointer, 10); + ret.integer() = std::strtoll(val.c_str(), &end_pointer, 10); #if TORRENT_USE_ASSERTS ret.m_type_queried = false; #endif diff --git a/include/libtorrent/http_parser.hpp b/include/libtorrent/http_parser.hpp index 678d1adf3..4210c3bc7 100644 --- a/include/libtorrent/http_parser.hpp +++ b/include/libtorrent/http_parser.hpp @@ -63,8 +63,7 @@ namespace libtorrent std::string const& header(char const* key) const { static std::string empty; - std::multimap::const_iterator i - = m_header.find(key); + auto const i = m_header.find(key); if (i == m_header.end()) return empty; return i->second; } diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 12dadee0b..25f2e61dd 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -246,7 +246,7 @@ void http_connection::start(std::string const& hostname, int port m_read_timeout = seconds(5); if (m_read_timeout < timeout / 5) m_read_timeout = timeout / 5; error_code ec; - m_timer.expires_from_now((std::min)( + m_timer.expires_from_now(std::min( m_read_timeout, m_completion_timeout), ec); ADD_OUTSTANDING_ASYNC("http_connection::on_timeout"); m_timer.async_wait(std::bind(&http_connection::on_timeout @@ -449,7 +449,7 @@ void http_connection::on_timeout(std::weak_ptr p ADD_OUTSTANDING_ASYNC("http_connection::on_timeout"); error_code ec; - c->m_timer.expires_at((std::min)( + c->m_timer.expires_at(std::min( c->m_last_receive + c->m_read_timeout , c->m_start_time + c->m_completion_timeout), ec); c->m_timer.async_wait(std::bind(&http_connection::on_timeout, p, _1)); diff --git a/src/http_parser.cpp b/src/http_parser.cpp index e4fc17ad9..1c3c49566 100644 --- a/src/http_parser.cpp +++ b/src/http_parser.cpp @@ -122,7 +122,7 @@ namespace libtorrent // however, we may still need to insert a '/' in case neither side // has one. We know the location doesn't start with a / already. // so, if the referrer doesn't end with one, add it. - if ((url.empty() || url[url.size()-1] != '/')) + if (url.empty() || url[url.size() - 1] != '/') url += '/'; url += location; } @@ -262,7 +262,7 @@ restart_response: if (name == "content-length") { - m_content_length = strtoll(value.c_str(), nullptr, 10); + m_content_length = std::strtoll(value.c_str(), nullptr, 10); if (m_content_length < 0) { m_state = error_state; @@ -285,7 +285,7 @@ restart_response: // start immediately if (string_begins_no_case("bytes ", ptr)) ptr += 6; char* end; - m_range_start = strtoll(ptr, &end, 10); + m_range_start = std::strtoll(ptr, &end, 10); if (m_range_start < 0) { m_state = error_state; @@ -297,7 +297,7 @@ restart_response: else { ptr = end + 1; - m_range_end = strtoll(ptr, &end, 10); + m_range_end = std::strtoll(ptr, &end, 10); if (m_range_end < 0) { m_state = error_state; @@ -454,7 +454,7 @@ restart_response: // empty line // first, read the chunk length - *chunk_size = strtoll(pos, nullptr, 16); + *chunk_size = std::strtoll(pos, nullptr, 16); if (*chunk_size < 0) return true; if (*chunk_size != 0) diff --git a/src/http_seed_connection.cpp b/src/http_seed_connection.cpp index faae45967..30edf84d2 100644 --- a/src/http_seed_connection.cpp +++ b/src/http_seed_connection.cpp @@ -79,7 +79,7 @@ namespace libtorrent } void http_seed_connection::disconnect(error_code const& ec - , operation_t op, int error) + , operation_t const op, int const error) { if (is_disconnecting()) return; @@ -155,7 +155,7 @@ namespace libtorrent { int request_offset = r.start + r.length - size; pr.start = request_offset % piece_size; - pr.length = (std::min)(block_size, size); + pr.length = std::min(block_size, size); pr.piece = piece_index_t(static_cast(r.piece) + request_offset / piece_size); m_requests.push_back(pr); size -= pr.length; diff --git a/src/torrent.cpp b/src/torrent.cpp index ebae4e120..5d4ffcae8 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -8177,7 +8177,7 @@ namespace libtorrent // TODO: add a flag to ignore stats, and only care about resume data for // content. For unchanged files, don't trigger a load of the metadata // just to save an empty resume data file - void torrent::save_resume_data(int flags) + void torrent::save_resume_data(int const flags) { TORRENT_ASSERT(is_single_thread()); INVARIANT_CHECK; diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index 78803ba52..244a582d6 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -158,7 +158,7 @@ enum // into account. if lhs is close to UINT_MAX and rhs // is close to 0, lhs is assumed to have wrapped and // considered smaller -TORRENT_EXTRA_EXPORT bool compare_less_wrap(std::uint32_t lhs +bool compare_less_wrap(std::uint32_t lhs , std::uint32_t rhs, std::uint32_t mask) { // distance walking from lhs to rhs, downwards diff --git a/test/test_http_connection.cpp b/test/test_http_connection.cpp index 9317bbff0..7afe2e3c9 100644 --- a/test/test_http_connection.cpp +++ b/test/test_http_connection.cpp @@ -60,10 +60,9 @@ void print_http_header(http_parser const& p) { std::cout << time_now_string() << " < " << p.status_code() << " " << p.message() << std::endl; - for (std::multimap::const_iterator i - = p.headers().begin(), end(p.headers().end()); i != end; ++i) + for (auto const& i : p.headers()) { - std::cout << time_now_string() << " < " << i->first << ": " << i->second << std::endl; + std::cout << time_now_string() << " < " << i.first << ": " << i.second << std::endl; } } diff --git a/test/test_socket_io.cpp b/test/test_socket_io.cpp index eeea9ef6b..5e1b221a6 100644 --- a/test/test_socket_io.cpp +++ b/test/test_socket_io.cpp @@ -140,7 +140,7 @@ TORRENT_TEST(parse_invalid_ipv4_endpoint) ec.clear(); #ifndef TORRENT_WINDOWS - // it appears windows siliently accepts truncated IP addresses + // it appears windows silently accepts truncated IP addresses endp = parse_endpoint("127.0.0:123", ec); TEST_CHECK(ec); ec.clear();