diff --git a/include/libtorrent/http_connection.hpp b/include/libtorrent/http_connection.hpp index 5d3f77a5e..1c5dc7852 100644 --- a/include/libtorrent/http_connection.hpp +++ b/include/libtorrent/http_connection.hpp @@ -144,7 +144,7 @@ private: void callback(error_code e, char* data = nullptr, int size = 0); - std::vector m_recvbuffer; + aux::vector m_recvbuffer; std::string m_hostname; std::string m_url; diff --git a/include/libtorrent/i2p_stream.hpp b/include/libtorrent/i2p_stream.hpp index 320d47f9f..bde9bc752 100644 --- a/include/libtorrent/i2p_stream.hpp +++ b/include/libtorrent/i2p_stream.hpp @@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/proxy_base.hpp" #include "libtorrent/session_settings.hpp" #include "libtorrent/string_util.hpp" +#include "libtorrent/aux_/vector.hpp" namespace libtorrent { @@ -139,7 +140,7 @@ private: void send_session_create(handler_type h); // send and receive buffer - std::vector m_buffer; + aux::vector m_buffer; char const* m_id; int m_command; // 0 = connect, 1 = accept std::string m_dest; diff --git a/include/libtorrent/kademlia/routing_table.hpp b/include/libtorrent/kademlia/routing_table.hpp index 511e5b316..4967eba3a 100644 --- a/include/libtorrent/kademlia/routing_table.hpp +++ b/include/libtorrent/kademlia/routing_table.hpp @@ -45,6 +45,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace libtorrent { @@ -58,7 +59,7 @@ namespace libtorrent { namespace dht { struct dht_logger; -typedef std::vector bucket_t; +typedef aux::vector bucket_t; struct routing_table_node { @@ -147,7 +148,7 @@ public: // TODO: 3 to improve memory locality and scanning performance, turn the // routing table into a single vector with boundaries for the nodes instead. // Perhaps replacement nodes should be in a separate vector. - using table_t = std::vector; + using table_t = aux::vector; routing_table(node_id const& id, udp proto , int bucket_size diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index ae7616a90..dce466c25 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -64,6 +64,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/span.hpp" #include "libtorrent/piece_block.hpp" #include "libtorrent/peer_info.hpp" +#include "libtorrent/aux_/vector.hpp" #include #include @@ -767,12 +768,12 @@ namespace libtorrent // the queue of blocks we have requested // from this peer - std::vector m_download_queue; + aux::vector m_download_queue; // the queue of requests we have got // from this peer that haven't been issued // to the disk thread yet - std::vector m_requests; + aux::vector m_requests; // this peer's peer info struct. This may // be 0, in case the connection is incoming diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 0f05a448d..080788f7c 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -727,7 +727,7 @@ namespace libtorrent // these are indices to the priority boundaries inside // the m_pieces vector. priority 0 always start at // 0, priority 1 starts at m_priority_boundaries[0] etc. - mutable std::vector m_priority_boundaries; + mutable aux::vector m_priority_boundaries; // each piece that's currently being downloaded has an entry in this list // with block allocations. i.e. it says which parts of the piece that is @@ -737,12 +737,12 @@ namespace libtorrent // corresponding downloading_piece vector is piece_open and // piece_downloading_reverse (the latter uses the same as // piece_downloading). - std::vector m_downloads[piece_pos::num_download_categories]; + aux::vector m_downloads[piece_pos::num_download_categories]; // this holds the information of the blocks in partially downloaded // pieces. the downloading_piece::info index point into this vector for // its storage - std::vector m_block_info; + aux::vector m_block_info; // these are block ranges in m_block_info that are free. The numbers // in here, when multiplied by m_blocks_per_piece is the index to the diff --git a/include/libtorrent/web_peer_connection.hpp b/include/libtorrent/web_peer_connection.hpp index 938c763de..4bb8bb94f 100644 --- a/include/libtorrent/web_peer_connection.hpp +++ b/include/libtorrent/web_peer_connection.hpp @@ -44,6 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/web_connection_base.hpp" #include "libtorrent/piece_block_progress.hpp" #include "libtorrent/operations.hpp" // for operation_t enum +#include "libtorrent/aux_/vector.hpp" namespace libtorrent { @@ -116,7 +117,7 @@ namespace libtorrent // TODO: 3 if we make this be a disk_buffer_holder instead // we would save a copy // use allocate_disk_receive_buffer and release_disk_receive_buffer - std::vector m_piece; + aux::vector m_piece; // the number of bytes we've forwarded to the incoming_payload() function // in the current HTTP response. used to know where in the buffer the diff --git a/src/http_connection.cpp b/src/http_connection.cpp index 28c117fa7..a1cdf58c5 100644 --- a/src/http_connection.cpp +++ b/src/http_connection.cpp @@ -841,7 +841,7 @@ void http_connection::on_read(error_code const& e } ADD_OUTSTANDING_ASYNC("http_connection::on_read"); m_sock.async_read_some(boost::asio::buffer(m_recvbuffer.data() + m_read_pos - , amount_to_read) + , std::size_t(amount_to_read)) , std::bind(&http_connection::on_read , me, _1, _2)); } @@ -871,7 +871,7 @@ void http_connection::on_assign_bandwidth(error_code const& e) ADD_OUTSTANDING_ASYNC("http_connection::on_read"); m_sock.async_read_some(boost::asio::buffer(m_recvbuffer.data() + m_read_pos - , amount_to_read) + , std::size_t(amount_to_read)) , std::bind(&http_connection::on_read , shared_from_this(), _1, _2)); diff --git a/src/http_parser.cpp b/src/http_parser.cpp index 898cb064d..aed740490 100644 --- a/src/http_parser.cpp +++ b/src/http_parser.cpp @@ -138,7 +138,7 @@ namespace libtorrent { TORRENT_ASSERT(recv_buffer.size() >= m_recv_buffer.size()); std::tuple ret(0, 0); - size_t start_pos = m_recv_buffer.size(); + std::size_t start_pos = m_recv_buffer.size(); // early exit if there's nothing new in the receive buffer if (start_pos == recv_buffer.size()) return ret; @@ -206,7 +206,7 @@ restart_response: m_status_code = 0; } m_state = read_header; - start_pos = pos - recv_buffer.data(); + start_pos = std::size_t(pos - recv_buffer.data()); } if (m_state == read_header) @@ -525,7 +525,7 @@ restart_response: ? (std::min)(m_chunked_ranges.back().second - m_body_start_pos, received) : m_content_length < 0 ? received : (std::min)(m_content_length, received); - return m_recv_buffer.subspan(m_body_start_pos, std::size_t(body_length)); + return m_recv_buffer.subspan(std::size_t(m_body_start_pos), std::size_t(body_length)); } void http_parser::reset() @@ -566,7 +566,7 @@ restart_response: TORRENT_ASSERT(i.second - offset <= size); int len = int(i.second - i.first); if (i.first - offset + len > size) len = size - int(i.first) + offset; - std::memmove(write_ptr, buffer + i.first - offset, len); + std::memmove(write_ptr, buffer + i.first - offset, std::size_t(len)); write_ptr += len; } size = int(write_ptr - buffer); diff --git a/src/http_tracker_connection.cpp b/src/http_tracker_connection.cpp index a7dc517e2..7c2f3b105 100644 --- a/src/http_tracker_connection.cpp +++ b/src/http_tracker_connection.cpp @@ -487,7 +487,7 @@ namespace libtorrent if (peers_ent && peers_ent.type() == bdecode_node::string_t) { char const* peers = peers_ent.string_ptr(); - int len = peers_ent.string_length(); + int const len = peers_ent.string_length(); #if TORRENT_USE_I2P if (0 != (flags & tracker_request::i2p)) { @@ -504,7 +504,7 @@ namespace libtorrent else #endif { - resp.peers4.reserve(len / 6); + resp.peers4.reserve(std::size_t(len / 6)); for (int i = 0; i < len; i += 6) { if (len - i < 6) break; @@ -546,8 +546,8 @@ namespace libtorrent if (ipv6_peers) { char const* peers = ipv6_peers.string_ptr(); - int len = ipv6_peers.string_length(); - resp.peers6.reserve(len / 18); + int const len = ipv6_peers.string_length(); + resp.peers6.reserve(std::size_t(len / 18)); for (int i = 0; i < len; i += 18) { if (len - i < 18) break; diff --git a/src/i2p_stream.cpp b/src/i2p_stream.cpp index 8337a0c24..2d5e53fef 100644 --- a/src/i2p_stream.cpp +++ b/src/i2p_stream.cpp @@ -455,7 +455,7 @@ namespace libtorrent int size = std::snprintf(cmd, sizeof(cmd), "STREAM CONNECT ID=%s DESTINATION=%s\n" , m_id, m_dest.c_str()); ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line"); - async_write(m_sock, boost::asio::buffer(cmd, size) + async_write(m_sock, boost::asio::buffer(cmd, std::size_t(size)) , std::bind(&i2p_stream::start_read_line, this, _1, std::move(h))); } @@ -466,7 +466,7 @@ namespace libtorrent char cmd[400]; int size = std::snprintf(cmd, sizeof(cmd), "STREAM ACCEPT ID=%s\n", m_id); ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line"); - async_write(m_sock, boost::asio::buffer(cmd, size) + async_write(m_sock, boost::asio::buffer(cmd, std::size_t(size)) , std::bind(&i2p_stream::start_read_line, this, _1, std::move(h))); } @@ -478,7 +478,7 @@ namespace libtorrent int size = std::snprintf(cmd, sizeof(cmd), "SESSION CREATE STYLE=STREAM ID=%s DESTINATION=TRANSIENT\n" , m_id); ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line"); - async_write(m_sock, boost::asio::buffer(cmd, size) + async_write(m_sock, boost::asio::buffer(cmd, std::size_t(size)) , std::bind(&i2p_stream::start_read_line, this, _1, std::move(h))); } @@ -489,7 +489,7 @@ namespace libtorrent char cmd[1024]; int size = std::snprintf(cmd, sizeof(cmd), "NAMING LOOKUP NAME=%s\n", m_name_lookup.c_str()); ADD_OUTSTANDING_ASYNC("i2p_stream::start_read_line"); - async_write(m_sock, boost::asio::buffer(cmd, size) + async_write(m_sock, boost::asio::buffer(cmd, std::size_t(size)) , std::bind(&i2p_stream::start_read_line, this, _1, std::move(h))); } } diff --git a/src/kademlia/dht_storage.cpp b/src/kademlia/dht_storage.cpp index bbaff0574..31cd71b38 100644 --- a/src/kademlia/dht_storage.cpp +++ b/src/kademlia/dht_storage.cpp @@ -261,7 +261,7 @@ namespace str.resize(18); std::string::iterator out = str.begin(); detail::write_endpoint(iter->addr, out); - str.resize(out - str.begin()); + str.resize(std::size_t(out - str.begin())); --to_pick; } diff --git a/src/kademlia/dht_tracker.cpp b/src/kademlia/dht_tracker.cpp index 3bcd385f0..e6635485a 100644 --- a/src/kademlia/dht_tracker.cpp +++ b/src/kademlia/dht_tracker.cpp @@ -589,12 +589,12 @@ namespace libtorrent { namespace dht bool dht_tracker::has_quota() { - time_point now = clock_type::now(); - time_duration delta = now - m_last_tick; + time_point const now = clock_type::now(); + time_duration const delta = now - m_last_tick; m_last_tick = now; // add any new quota we've accrued since last time - m_send_quota += int(std::uint64_t(m_settings.upload_rate_limit) + m_send_quota += int(std::int64_t(m_settings.upload_rate_limit) * total_microseconds(delta) / 1000000); // allow 3 seconds worth of burst @@ -629,7 +629,7 @@ namespace libtorrent { namespace dht return false; } - m_counters.inc_stats_counter(counters::dht_bytes_out, m_send_buf.size()); + m_counters.inc_stats_counter(counters::dht_bytes_out, int(m_send_buf.size())); // account for IP and UDP overhead m_counters.inc_stats_counter(counters::sent_ip_overhead_bytes , addr.address().is_v6() ? 48 : 28); diff --git a/src/part_file.cpp b/src/part_file.cpp index 643c6f869..f1e0f35aa 100644 --- a/src/part_file.cpp +++ b/src/part_file.cpp @@ -105,8 +105,8 @@ namespace libtorrent char* ptr = reinterpret_cast(header.get()); // we have a header. Parse it - int num_pieces_ = read_uint32(ptr); - int piece_size_ = read_uint32(ptr); + int const num_pieces_ = int(read_uint32(ptr)); + int const piece_size_ = int(read_uint32(ptr)); // if there is a mismatch in number of pieces or piece size // consider the file empty and overwrite anything in there @@ -407,7 +407,7 @@ namespace libtorrent ? slot_index_t(-1) : i->second); write_int32(static_cast(slot), ptr); } - std::memset(ptr, 0, m_header_size - (ptr - reinterpret_cast(header.get()))); + std::memset(ptr, 0, std::size_t(m_header_size - (ptr - reinterpret_cast(header.get())))); iovec_t b = {header.get(), std::size_t(m_header_size)}; m_file.writev(0, b, ec); diff --git a/src/session_stats.cpp b/src/session_stats.cpp index 568b7783d..fd46a1d3b 100644 --- a/src/session_stats.cpp +++ b/src/session_stats.cpp @@ -535,7 +535,7 @@ namespace libtorrent std::vector stats; int const num = sizeof(metrics) / sizeof(metrics[0]); stats.resize(num); - for (int i = 0; i < num; ++i) + for (std::size_t i = 0; i < num; ++i) { stats[i].name = metrics[i].name; stats[i].value_index = metrics[i].value_index; diff --git a/src/socks5_stream.cpp b/src/socks5_stream.cpp index 20c6e3496..59157b496 100644 --- a/src/socks5_stream.cpp +++ b/src/socks5_stream.cpp @@ -427,7 +427,7 @@ namespace libtorrent } return; } - int extra_bytes = 0; + std::size_t extra_bytes = 0; if (atyp == 4) { // IPv6 diff --git a/src/storage.cpp b/src/storage.cpp index cf2330428..c59ad30e8 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -864,7 +864,7 @@ namespace libtorrent // indices of all files we ended up copying. These need to be deleted // later - aux::vector copied_files(f.num_files(), false); + aux::vector copied_files(std::size_t(f.num_files()), false); file_index_t i; error_code e; @@ -1176,10 +1176,10 @@ namespace libtorrent , piece_index_t, int, int, storage_error&) override { int ret = 0; - for (int i = 0; i < int(bufs.size()); ++i) + for (auto const& b : bufs) { - memset(bufs[i].iov_base, 0, bufs[i].iov_len); - ret += int(bufs[i].iov_len); + std::memset(b.iov_base, 0, b.iov_len); + ret += int(b.iov_len); } return 0; } @@ -1187,8 +1187,8 @@ namespace libtorrent , piece_index_t, int, int, storage_error&) override { int ret = 0; - for (int i = 0; i < int(bufs.size()); ++i) - ret += int(bufs[i].iov_len); + for (auto const& b : bufs) + ret += int(b.iov_len); return 0; } diff --git a/src/string_util.cpp b/src/string_util.cpp index f1ad3946e..0608c90f3 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -47,12 +47,12 @@ namespace libtorrent // lexical_cast's result depends on the locale. We need // a well defined result std::array::digits10> - to_string(std::int64_t n) + to_string(std::int64_t const n) { std::array::digits10> ret; char *p = &ret.back(); *p = '\0'; - std::uint64_t un = n; + std::uint64_t un = std::uint64_t(n); #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable : 4146 ) /* warning C4146: unary minus operator applied to unsigned type */ @@ -66,7 +66,7 @@ namespace libtorrent un /= 10; } while (un); if (n < 0) *--p = '-'; - std::memmove(&ret[0], p, &ret.back() - p + 1); + std::memmove(ret.data(), p, std::size_t(&ret.back() - p + 1)); return ret; } @@ -160,7 +160,7 @@ namespace libtorrent char* allocate_string_copy(char const* str) { if (str == nullptr) return nullptr; - int const len = int(std::strlen(str)); + std::size_t const len = std::strlen(str); char* tmp = static_cast(std::malloc(len + 1)); if (tmp == nullptr) return nullptr; std::memcpy(tmp, str, len); diff --git a/src/udp_tracker_connection.cpp b/src/udp_tracker_connection.cpp index bd34d9515..c2459ced3 100644 --- a/src/udp_tracker_connection.cpp +++ b/src/udp_tracker_connection.cpp @@ -618,7 +618,7 @@ namespace libtorrent return true; } - resp.peers4.reserve(num_peers); + resp.peers4.reserve(std::size_t(num_peers)); for (int i = 0; i < num_peers; ++i) { ipv4_peer_entry e; diff --git a/src/utp_socket_manager.cpp b/src/utp_socket_manager.cpp index 7603deaae..a14e899d7 100644 --- a/src/utp_socket_manager.cpp +++ b/src/utp_socket_manager.cpp @@ -136,11 +136,11 @@ namespace libtorrent else mtu -= TORRENT_IPV6_HEADER; } - utp_mtu = (std::min)(mtu, restrict_mtu()); + utp_mtu = std::min(mtu, restrict_mtu()); } void utp_socket_manager::send_packet(udp::endpoint const& ep, char const* p - , int len, error_code& ec, int flags) + , int const len, error_code& ec, int const flags) { #if !defined TORRENT_HAS_DONT_FRAGMENT && !defined TORRENT_DEBUG_MTU TORRENT_UNUSED(flags); @@ -151,7 +151,7 @@ namespace libtorrent if ((flags & dont_fragment) && len > TORRENT_DEBUG_MTU) return; #endif - m_send_fun(ep, span(p, len), ec + m_send_fun(ep, {p, std::size_t(len)}, ec , ((flags & dont_fragment) ? udp_socket::dont_fragment : 0) | udp_socket::peer_connection); }