mirror of
https://github.com/transmission/transmission.git
synced 2025-12-19 18:08:31 +00:00
refactor: snake_case in libtransmission class methods (#5428)
This commit is contained in:
@@ -29,37 +29,37 @@ public:
|
||||
|
||||
tr_block_info(uint64_t total_size_in, uint32_t piece_size_in) noexcept
|
||||
{
|
||||
initSizes(total_size_in, piece_size_in);
|
||||
init_sizes(total_size_in, piece_size_in);
|
||||
}
|
||||
|
||||
void initSizes(uint64_t total_size_in, uint32_t piece_size_in) noexcept;
|
||||
void init_sizes(uint64_t total_size_in, uint32_t piece_size_in) noexcept;
|
||||
|
||||
[[nodiscard]] constexpr auto blockCount() const noexcept
|
||||
[[nodiscard]] constexpr auto block_count() const noexcept
|
||||
{
|
||||
return n_blocks_;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto blockSize(tr_block_index_t block) const noexcept
|
||||
[[nodiscard]] constexpr auto block_size(tr_block_index_t block) const noexcept
|
||||
{
|
||||
return block + 1 == n_blocks_ ? final_block_size_ : BlockSize;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto pieceCount() const noexcept
|
||||
[[nodiscard]] constexpr auto piece_count() const noexcept
|
||||
{
|
||||
return n_pieces_;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto pieceSize() const noexcept
|
||||
[[nodiscard]] constexpr auto piece_size() const noexcept
|
||||
{
|
||||
return piece_size_;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto pieceSize(tr_piece_index_t piece) const noexcept
|
||||
[[nodiscard]] constexpr auto piece_size(tr_piece_index_t piece) const noexcept
|
||||
{
|
||||
return piece + 1 == n_pieces_ ? final_piece_size_ : pieceSize();
|
||||
return piece + 1 == n_pieces_ ? final_piece_size_ : piece_size();
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr auto totalSize() const noexcept
|
||||
[[nodiscard]] constexpr auto total_size() const noexcept
|
||||
{
|
||||
return total_size_;
|
||||
}
|
||||
@@ -86,73 +86,73 @@ public:
|
||||
};
|
||||
|
||||
// Location of the torrent's nth byte
|
||||
[[nodiscard]] constexpr auto byteLoc(uint64_t byte_idx) const noexcept
|
||||
[[nodiscard]] constexpr auto byte_loc(uint64_t byte_idx) const noexcept
|
||||
{
|
||||
auto loc = Location{};
|
||||
|
||||
if (isInitialized())
|
||||
if (is_initialized())
|
||||
{
|
||||
loc.byte = byte_idx;
|
||||
|
||||
if (byte_idx == totalSize()) // handle 0-byte files at the end of a torrent
|
||||
if (byte_idx == total_size()) // handle 0-byte files at the end of a torrent
|
||||
{
|
||||
loc.block = blockCount() - 1;
|
||||
loc.piece = pieceCount() - 1;
|
||||
loc.block = block_count() - 1;
|
||||
loc.piece = piece_count() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
loc.block = byte_idx / BlockSize;
|
||||
loc.piece = byte_idx / pieceSize();
|
||||
loc.piece = byte_idx / piece_size();
|
||||
}
|
||||
|
||||
loc.block_offset = static_cast<uint32_t>(loc.byte - (uint64_t{ loc.block } * BlockSize));
|
||||
loc.piece_offset = static_cast<uint32_t>(loc.byte - (uint64_t{ loc.piece } * pieceSize()));
|
||||
loc.piece_offset = static_cast<uint32_t>(loc.byte - (uint64_t{ loc.piece } * piece_size()));
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
|
||||
// Location of the first byte in `block`.
|
||||
[[nodiscard]] constexpr auto blockLoc(tr_block_index_t block) const noexcept
|
||||
[[nodiscard]] constexpr auto block_loc(tr_block_index_t block) const noexcept
|
||||
{
|
||||
return byteLoc(uint64_t{ block } * BlockSize);
|
||||
return byte_loc(uint64_t{ block } * BlockSize);
|
||||
}
|
||||
|
||||
// Location of the first byte (+ optional offset and length) in `piece`
|
||||
[[nodiscard]] constexpr auto pieceLoc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept
|
||||
[[nodiscard]] constexpr auto piece_loc(tr_piece_index_t piece, uint32_t offset = 0, uint32_t length = 0) const noexcept
|
||||
{
|
||||
return byteLoc(uint64_t{ piece } * pieceSize() + offset + length);
|
||||
return byte_loc(uint64_t{ piece } * piece_size() + offset + length);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr tr_block_span_t blockSpanForPiece(tr_piece_index_t piece) const noexcept
|
||||
[[nodiscard]] constexpr tr_block_span_t block_span_for_piece(tr_piece_index_t piece) const noexcept
|
||||
{
|
||||
if (!isInitialized())
|
||||
if (!is_initialized())
|
||||
{
|
||||
return { 0U, 0U };
|
||||
}
|
||||
|
||||
return { pieceLoc(piece).block, pieceLastLoc(piece).block + 1 };
|
||||
return { piece_loc(piece).block, piece_last_loc(piece).block + 1 };
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr tr_byte_span_t byteSpanForPiece(tr_piece_index_t piece) const noexcept
|
||||
[[nodiscard]] constexpr tr_byte_span_t byte_span_for_piece(tr_piece_index_t piece) const noexcept
|
||||
{
|
||||
if (!isInitialized())
|
||||
if (!is_initialized())
|
||||
{
|
||||
return { 0U, 0U };
|
||||
}
|
||||
|
||||
auto const offset = pieceLoc(piece).byte;
|
||||
return { offset, offset + pieceSize(piece) };
|
||||
auto const offset = piece_loc(piece).byte;
|
||||
return { offset, offset + piece_size(piece) };
|
||||
}
|
||||
|
||||
private:
|
||||
// Location of the last byte in `piece`.
|
||||
[[nodiscard]] constexpr Location pieceLastLoc(tr_piece_index_t piece) const noexcept
|
||||
[[nodiscard]] constexpr Location piece_last_loc(tr_piece_index_t piece) const noexcept
|
||||
{
|
||||
return byteLoc(static_cast<uint64_t>(piece) * pieceSize() + pieceSize(piece) - 1);
|
||||
return byte_loc(static_cast<uint64_t>(piece) * piece_size() + piece_size(piece) - 1);
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr bool isInitialized() const noexcept
|
||||
[[nodiscard]] constexpr bool is_initialized() const noexcept
|
||||
{
|
||||
return piece_size_ != 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user