1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-22 06:00:41 +00:00
transmission/libtransmission/block-info.cc
Charles Kerr 56837517b0
refactor: tr_block_info cleanup (#6342)
* refactor: make tr_block_info::init_sizes() private

* refactor: remove unuse tr_file_piece_map::empty()

* refactor: remove tr_file_priorities::reset()

* refactor: remove tr_files_wanted::reset()

* refactor: rename method to tr_file_piece_map::piece_span_for_file()

more consistent naming with tr_block_info

* refactor: rename method to tr_file_piece_map::file_span_for_piece()

more consistent naming with tr_block_info

* refactor: use standard class field order in tr_block_info

* refactor: move CompareToSpan from header to cc file

* refactor: make tr_file_piece_map::reset() private

* refactor: rename method to tr_file_piece_map::file_count()

* refactor: rename method to tr_file_piece_map::byte_span_for_file()

* refactor: constify tr_block_info function args

* refactor: fix more signed vs unsigned
2023-12-05 22:06:27 -06:00

30 lines
1,002 B
C++

// This file Copyright © Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#include <cstdint>
#include "libtransmission/block-info.h"
#include "libtransmission/tr-assert.h" // TR_ASSERT
void tr_block_info::init_sizes(uint64_t const total_size_in, uint32_t const piece_size_in) noexcept
{
TR_ASSERT(piece_size_in == 0 || piece_size_in >= BlockSize);
if (piece_size_in == 0)
{
*this = {};
return;
}
total_size_ = total_size_in;
piece_size_ = piece_size_in;
n_pieces_ = (total_size_ + piece_size_ - 1) / piece_size_;
n_blocks_ = (total_size_ + BlockSize - 1) / BlockSize;
uint32_t remainder = total_size_ % piece_size_;
final_piece_size_ = remainder != 0U ? remainder : piece_size_;
remainder = total_size_ % BlockSize;
final_block_size_ = remainder != 0U ? remainder : BlockSize;
}