forked from premiere/premiere-libtorrent
more std:: prefix, consts, auto refactor, formatting
This commit is contained in:
parent
22b745d548
commit
070e85090b
|
@ -40,7 +40,7 @@ namespace libtorrent { namespace aux {
|
|||
#if defined __GNUC__ && __GNUC__ < 5
|
||||
|
||||
// this is for backwards compatibility with not-quite C++11 compilers
|
||||
template <size_t Len, size_t Align = alignof(void*)>
|
||||
template <std::size_t Len, std::size_t Align = alignof(void*)>
|
||||
struct aligned_storage
|
||||
{
|
||||
struct type
|
||||
|
@ -58,4 +58,3 @@ using std::aligned_storage;
|
|||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -39,18 +39,18 @@ namespace libtorrent { namespace aux {
|
|||
|
||||
#if defined __GNUC__ && __GNUC__ < 5
|
||||
|
||||
constexpr std::size_t max(size_t a)
|
||||
constexpr std::size_t max(std::size_t a)
|
||||
{ return a; }
|
||||
|
||||
constexpr std::size_t max(size_t a, size_t b)
|
||||
constexpr std::size_t max(std::size_t a, std::size_t b)
|
||||
{ return a > b ? a : b; }
|
||||
|
||||
template <typename... Vals>
|
||||
constexpr std::size_t max(size_t a, size_t b, Vals... v)
|
||||
constexpr std::size_t max(std::size_t a, std::size_t b, Vals... v)
|
||||
{ return max(a, max(b, v...)); }
|
||||
|
||||
// this is for backwards compatibility with not-quite C++11 compilers
|
||||
template <size_t Len, typename... Types>
|
||||
template <std::size_t Len, typename... Types>
|
||||
struct aligned_union
|
||||
{
|
||||
struct type
|
||||
|
@ -69,4 +69,3 @@ using std::aligned_union;
|
|||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -116,4 +116,3 @@ namespace libtorrent { namespace aux {
|
|||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -566,7 +566,7 @@ namespace libtorrent
|
|||
|
||||
// if the backing buffer changed for this storage, this is the pointer
|
||||
// offset to add to any pointers to make them point into the new buffer
|
||||
void apply_pointer_offset(ptrdiff_t off);
|
||||
void apply_pointer_offset(std::ptrdiff_t off);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace libtorrent
|
|||
: m_ptr(v.data()), m_len(v.size()) {}
|
||||
|
||||
span(T& p) : m_ptr(&p), m_len(1) {} // NOLINT
|
||||
span(T* p, size_t const l) : m_ptr(p), m_len(l) {} // NOLINT
|
||||
span(T* p, std::size_t const l) : m_ptr(p), m_len(l) {} // NOLINT
|
||||
|
||||
template <typename U, std::size_t N>
|
||||
span(std::array<U, N>& arr) // NOLINT
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace libtorrent
|
|||
|
||||
// the number of failed connection attempts
|
||||
// this torrent_peer has
|
||||
unsigned failcount:5; // [0, 31]
|
||||
std::uint32_t failcount:5; // [0, 31]
|
||||
|
||||
// incoming peers (that don't advertise their listen port)
|
||||
// will not be considered connectable. Peers that
|
||||
|
@ -132,7 +132,7 @@ namespace libtorrent
|
|||
|
||||
// the number of times we have allowed a fast
|
||||
// reconnect for this torrent_peer.
|
||||
unsigned fast_reconnects:4;
|
||||
std::uint32_t fast_reconnects:4;
|
||||
|
||||
// for every valid piece we receive where this
|
||||
// torrent_peer was one of the participants, we increase
|
||||
|
@ -144,7 +144,7 @@ namespace libtorrent
|
|||
|
||||
// a bitmap combining the peer_source flags
|
||||
// from peer_info.
|
||||
unsigned source:6;
|
||||
std::uint32_t source:6;
|
||||
|
||||
#if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS)
|
||||
// Hints encryption support of torrent_peer. Only effective
|
||||
|
|
|
@ -51,8 +51,8 @@ namespace libtorrent
|
|||
int const rest = size() & 31;
|
||||
if (rest > 0)
|
||||
{
|
||||
std::uint32_t const mask = aux::host_to_network(0xffffffff << (32-rest));
|
||||
if ((m_buf[words+1] & mask) != mask) return false;
|
||||
std::uint32_t const mask = aux::host_to_network(0xffffffff << (32 - rest));
|
||||
if ((m_buf[words + 1] & mask) != mask) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -143,19 +143,19 @@ namespace libtorrent
|
|||
if (old_size_words && b) buf()[old_size_words - 1] |= aux::host_to_network((0xffffffff >> b));
|
||||
if (old_size_words < new_size_words)
|
||||
std::memset(buf() + old_size_words, 0xff
|
||||
, size_t((new_size_words - old_size_words) * 4));
|
||||
, std::size_t((new_size_words - old_size_words) * 4));
|
||||
clear_trailing_bits();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (old_size_words < new_size_words)
|
||||
std::memset(buf() + old_size_words, 0x00
|
||||
, size_t((new_size_words - old_size_words) * 4));
|
||||
, std::size_t((new_size_words - old_size_words) * 4));
|
||||
}
|
||||
TORRENT_ASSERT(size() == bits);
|
||||
}
|
||||
|
||||
void bitfield::resize(int bits)
|
||||
void bitfield::resize(int const bits)
|
||||
{
|
||||
if (bits == size()) return;
|
||||
|
||||
|
@ -174,7 +174,7 @@ namespace libtorrent
|
|||
if (b == nullptr) std::terminate();
|
||||
#endif
|
||||
b[0] = bits;
|
||||
if (m_buf) std::memcpy(&b[1], buf(), (std::min)(new_size_words, cur_size_words) * 4);
|
||||
if (m_buf) std::memcpy(&b[1], buf(), std::min(new_size_words, cur_size_words) * 4);
|
||||
if (new_size_words > cur_size_words)
|
||||
{
|
||||
std::memset(&b[1 + cur_size_words], 0
|
||||
|
@ -193,7 +193,7 @@ namespace libtorrent
|
|||
|
||||
int bitfield::find_first_set() const
|
||||
{
|
||||
size_t const num = num_words();
|
||||
std::size_t const num = num_words();
|
||||
if (num == 0) return -1;
|
||||
int const count = aux::count_leading_zeros({&m_buf[1], num});
|
||||
return count != int(num) * 32 ? count : -1;
|
||||
|
@ -201,7 +201,7 @@ namespace libtorrent
|
|||
|
||||
int bitfield::find_last_clear() const
|
||||
{
|
||||
size_t const num = num_words();
|
||||
std::size_t const num = num_words();
|
||||
if (num == 0) return - 1;
|
||||
int const size = this->size();
|
||||
std::uint32_t const mask = 0xffffffff << (32 - (size & 31));
|
||||
|
|
|
@ -34,27 +34,27 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace libtorrent
|
||||
{
|
||||
bool has_bits(std::uint8_t const* k, std::uint8_t const* bits, int len)
|
||||
bool has_bits(std::uint8_t const* k, std::uint8_t const* bits, int const len)
|
||||
{
|
||||
std::uint32_t idx1 = std::uint32_t(k[0]) | (std::uint32_t(k[1]) << 8);
|
||||
std::uint32_t idx2 = std::uint32_t(k[2]) | (std::uint32_t(k[3]) << 8);
|
||||
idx1 %= len * 8;
|
||||
idx2 %= len * 8;
|
||||
return (bits[idx1/8] & (1 << (idx1 & 7))) != 0
|
||||
&& (bits[idx2/8] & (1 << (idx2 & 7))) != 0;
|
||||
return (bits[idx1 / 8] & (1 << (idx1 & 7))) != 0
|
||||
&& (bits[idx2 / 8] & (1 << (idx2 & 7))) != 0;
|
||||
}
|
||||
|
||||
void set_bits(std::uint8_t const* k, std::uint8_t* bits, int len)
|
||||
void set_bits(std::uint8_t const* k, std::uint8_t* bits, int const len)
|
||||
{
|
||||
std::uint32_t idx1 = std::uint32_t(k[0]) | (std::uint32_t(k[1]) << 8);
|
||||
std::uint32_t idx2 = std::uint32_t(k[2]) | (std::uint32_t(k[3]) << 8);
|
||||
idx1 %= len * 8;
|
||||
idx2 %= len * 8;
|
||||
bits[idx1/8] |= (1 << (idx1 & 7));
|
||||
bits[idx2/8] |= (1 << (idx2 & 7));
|
||||
bits[idx1 / 8] |= (1 << (idx1 & 7));
|
||||
bits[idx2 / 8] |= (1 << (idx2 & 7));
|
||||
}
|
||||
|
||||
int count_zero_bits(std::uint8_t const* bits, int len)
|
||||
int count_zero_bits(std::uint8_t const* bits, int const len)
|
||||
{
|
||||
// number of bits _not_ set in a nibble
|
||||
std::uint8_t bitcount[16] =
|
||||
|
|
|
@ -3186,8 +3186,8 @@ namespace libtorrent
|
|||
{
|
||||
for (int j=0; j < 8; ++j)
|
||||
{
|
||||
if (recv_buffer[i] & (0x80 >> j)) extensions[i*8+j] = '1';
|
||||
else extensions[i*8+j] = '0';
|
||||
if (recv_buffer[i] & (0x80 >> j)) extensions[i * 8 + j] = '1';
|
||||
else extensions[i * 8 + j] = '0';
|
||||
}
|
||||
}
|
||||
if (should_log(peer_log_alert::incoming_message))
|
||||
|
|
|
@ -545,7 +545,7 @@ namespace libtorrent
|
|||
--pe->piece_refcount;
|
||||
m_disk_cache.maybe_free_piece(pe);
|
||||
}
|
||||
const int block_diff = iovec_offset[i+1] - iovec_offset[i];
|
||||
const int block_diff = iovec_offset[i + 1] - iovec_offset[i];
|
||||
iovec_flushed(pe, flushing.subspan(iovec_offset[i]).data(), block_diff
|
||||
, block_start, error, completed_jobs);
|
||||
block_start += int(p->blocks_in_piece);
|
||||
|
@ -617,7 +617,7 @@ namespace libtorrent
|
|||
|
||||
flushing[num_flushing++] = i + block_base_index;
|
||||
iov[iov_len].iov_base = pe->blocks[i].buf;
|
||||
iov[iov_len].iov_len = (std::min)(block_size, size_left);
|
||||
iov[iov_len].iov_len = std::min(block_size, size_left);
|
||||
++iov_len;
|
||||
pe->blocks[i].pending = true;
|
||||
|
||||
|
@ -1282,7 +1282,7 @@ namespace libtorrent
|
|||
|
||||
// if this is the last piece, adjust the size of the
|
||||
// last buffer to match up
|
||||
iov[iov_len - 1].iov_len = (std::min)(int(piece_size - adjusted_offset)
|
||||
iov[iov_len - 1].iov_len = std::min(int(piece_size - adjusted_offset)
|
||||
- (iov_len - 1) * block_size, block_size);
|
||||
TORRENT_ASSERT(iov[iov_len - 1].iov_len > 0);
|
||||
|
||||
|
@ -2153,7 +2153,7 @@ namespace libtorrent
|
|||
|
||||
time_point const start_time = clock_type::now();
|
||||
|
||||
iov.iov_len = (std::min)(block_size, piece_size - offset);
|
||||
iov.iov_len = std::min(block_size, piece_size - offset);
|
||||
ret = j->storage->readv(iov, j->piece
|
||||
, offset, file_flags, j->error);
|
||||
if (ret < 0) break;
|
||||
|
@ -2306,7 +2306,7 @@ namespace libtorrent
|
|||
for (int i = offset / block_size; i < blocks_in_piece; ++i)
|
||||
{
|
||||
iovec_t iov;
|
||||
iov.iov_len = (std::min)(block_size, piece_size - offset);
|
||||
iov.iov_len = std::min(block_size, piece_size - offset);
|
||||
|
||||
if (next_locked_block < num_locked_blocks
|
||||
&& locked_blocks[next_locked_block] == i)
|
||||
|
|
|
@ -107,4 +107,3 @@ namespace libtorrent
|
|||
m_job_pool.free(j[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ namespace libtorrent
|
|||
|
||||
char msg[TORRENT_MAX_PATH*4];
|
||||
std::snprintf(msg, sizeof(msg), "%s://%s%s%s%s%s%s", protocol.c_str(), auth.c_str()
|
||||
, auth.empty()?"":"@", host.c_str()
|
||||
, auth.empty() ? "" : "@", host.c_str()
|
||||
, port == -1 ? "" : ":"
|
||||
, port == -1 ? "" : to_string(port).data()
|
||||
, escape_path(path).c_str());
|
||||
|
|
|
@ -92,12 +92,12 @@ namespace libtorrent { namespace aux
|
|||
#endif
|
||||
|
||||
TORRENT_ASSERT(total_size >= off);
|
||||
std::int64_t size = (std::min)(std::int64_t(piece_size), total_size - off);
|
||||
std::int64_t size = std::min(std::int64_t(piece_size), total_size - off);
|
||||
TORRENT_ASSERT(size >= 0);
|
||||
|
||||
while (size)
|
||||
{
|
||||
std::int64_t const add = (std::min)(size, fs.file_size(file_index) - file_offset);
|
||||
std::int64_t const add = std::min(size, fs.file_size(file_index) - file_offset);
|
||||
TORRENT_ASSERT(add >= 0);
|
||||
m_file_progress[file_index] += add;
|
||||
|
||||
|
|
|
@ -318,7 +318,7 @@ namespace libtorrent
|
|||
return name ? string_view(name) : string_view();
|
||||
}
|
||||
|
||||
void file_storage::apply_pointer_offset(ptrdiff_t const off)
|
||||
void file_storage::apply_pointer_offset(std::ptrdiff_t const off)
|
||||
{
|
||||
for (auto& f : m_files)
|
||||
{
|
||||
|
@ -465,7 +465,7 @@ namespace libtorrent
|
|||
+ file_base_deprecated(f.file_index)
|
||||
#endif
|
||||
;
|
||||
f.size = (std::min)(std::uint64_t(file_iter->size) - file_offset, std::uint64_t(size));
|
||||
f.size = std::min(std::uint64_t(file_iter->size) - file_offset, std::uint64_t(size));
|
||||
TORRENT_ASSERT(f.size <= size);
|
||||
size -= int(f.size);
|
||||
file_offset += f.size;
|
||||
|
@ -670,9 +670,8 @@ namespace libtorrent
|
|||
crc.process_byte(TORRENT_SEPARATOR);
|
||||
}
|
||||
|
||||
for (int i = 0; i != int(m_paths.size()); ++i)
|
||||
for (auto const& p : m_paths)
|
||||
{
|
||||
std::string const& p = m_paths[i];
|
||||
process_path_lowercase(table, crc, p.c_str(), int(p.size()));
|
||||
}
|
||||
}
|
||||
|
@ -933,7 +932,7 @@ namespace libtorrent
|
|||
if (!m_mtime.empty())
|
||||
{
|
||||
TORRENT_ASSERT(m_mtime.size() == m_files.size());
|
||||
if (int(m_mtime.size()) < index) m_mtime.resize(index+1, 0);
|
||||
if (int(m_mtime.size()) < index) m_mtime.resize(index + 1, 0);
|
||||
std::iter_swap(m_mtime.begin() + dst, m_mtime.begin() + index);
|
||||
}
|
||||
if (!m_file_hashes.empty())
|
||||
|
|
|
@ -522,8 +522,8 @@ restart_response:
|
|||
std::int64_t const received = m_recv_pos - m_body_start_pos;
|
||||
|
||||
std::int64_t const body_length = m_chunked_encoding && !m_chunked_ranges.empty()
|
||||
? (std::min)(m_chunked_ranges.back().second - m_body_start_pos, received)
|
||||
: m_content_length < 0 ? received : (std::min)(m_content_length, received);
|
||||
? 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(std::size_t(m_body_start_pos), std::size_t(body_length));
|
||||
}
|
||||
|
|
|
@ -284,7 +284,7 @@ namespace libtorrent
|
|||
COMPLETE_ASYNC("i2p_stream::read_line");
|
||||
if (handle_error(e, h)) return;
|
||||
|
||||
int read_pos = int(m_buffer.size());
|
||||
int const read_pos = int(m_buffer.size());
|
||||
|
||||
// look for \n which means end of the response
|
||||
if (m_buffer[read_pos - 1] != '\n')
|
||||
|
@ -313,7 +313,7 @@ namespace libtorrent
|
|||
|
||||
// 0-terminate the string and parse it
|
||||
m_buffer.push_back(0);
|
||||
char* ptr = &m_buffer[0];
|
||||
char* ptr = m_buffer.data();
|
||||
char* next = ptr;
|
||||
|
||||
char const* expect1 = nullptr;
|
||||
|
|
|
@ -980,7 +980,7 @@ void node::incoming_request(msg const& m, entry& e)
|
|||
|
||||
span<char const> salt;
|
||||
if (msg_keys[6])
|
||||
salt = { msg_keys[6].string_ptr(), size_t(msg_keys[6].string_length()) };
|
||||
salt = {msg_keys[6].string_ptr(), std::size_t(msg_keys[6].string_length())};
|
||||
if (salt.size() > 64)
|
||||
{
|
||||
m_counters.inc_stats_counter(counters::dht_invalid_put);
|
||||
|
|
|
@ -217,7 +217,7 @@ int routing_table::depth() const
|
|||
if (m_depth < 0) return m_depth;
|
||||
|
||||
// maybe the table is deeper now?
|
||||
while (m_depth < int(m_buckets.size())-1
|
||||
while (m_depth < int(m_buckets.size()) - 1
|
||||
&& int(m_buckets[m_depth + 1].live_nodes.size()) >= m_bucket_size / 2)
|
||||
{
|
||||
++m_depth;
|
||||
|
@ -897,7 +897,7 @@ void routing_table::split_bucket()
|
|||
if (int(b.size()) > bucket_size_limit)
|
||||
{
|
||||
// TODO: 2 move the lowest priority nodes to the replacement bucket
|
||||
for (bucket_t::iterator i = b.begin() + bucket_size_limit
|
||||
for (auto i = b.begin() + bucket_size_limit
|
||||
, end(b.end()); i != end; ++i)
|
||||
{
|
||||
rb.push_back(*i);
|
||||
|
@ -909,7 +909,7 @@ void routing_table::split_bucket()
|
|||
// split the replacement bucket as well. If the live bucket
|
||||
// is not full anymore, also move the replacement entries
|
||||
// into the main bucket
|
||||
for (bucket_t::iterator j = rb.begin(); j != rb.end();)
|
||||
for (auto j = rb.begin(); j != rb.end();)
|
||||
{
|
||||
if (distance_exp(m_id, j->id) >= 159 - bucket_index)
|
||||
{
|
||||
|
@ -1066,7 +1066,7 @@ void routing_table::find_node(node_id const& target
|
|||
l.clear();
|
||||
if (count == 0) count = m_bucket_size;
|
||||
|
||||
table_t::iterator i = find_bucket(target);
|
||||
auto const i = find_bucket(target);
|
||||
int const bucket_index = int(std::distance(m_buckets.begin(), i));
|
||||
int const bucket_size_limit = bucket_limit(bucket_index);
|
||||
|
||||
|
@ -1077,7 +1077,7 @@ void routing_table::find_node(node_id const& target
|
|||
int unsorted_start_idx = 0;
|
||||
for (; j != m_buckets.end() && int(l.size()) < count; ++j)
|
||||
{
|
||||
bucket_t& b = j->live_nodes;
|
||||
bucket_t const& b = j->live_nodes;
|
||||
if (options & include_failed)
|
||||
{
|
||||
std::copy(b.begin(), b.end(), std::back_inserter(l));
|
||||
|
@ -1115,7 +1115,7 @@ void routing_table::find_node(node_id const& target
|
|||
do
|
||||
{
|
||||
--j;
|
||||
bucket_t& b = j->live_nodes;
|
||||
bucket_t const& b = j->live_nodes;
|
||||
|
||||
if (options & include_failed)
|
||||
{
|
||||
|
@ -1170,7 +1170,7 @@ void routing_table::check_invariant() const
|
|||
|
||||
bool routing_table::is_full(int const bucket) const
|
||||
{
|
||||
int num_buckets = int(m_buckets.size());
|
||||
int const num_buckets = int(m_buckets.size());
|
||||
if (num_buckets == 0) return false;
|
||||
if (bucket >= num_buckets) return false;
|
||||
|
||||
|
|
Loading…
Reference in New Issue