1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00
transmission/libtransmission/block-info.cc
Charles Kerr da3d83eaed
refactor: make blockinfo methods constexpr (#3682)
this can be constexpr and is an outlier in CPU profiling.
2022-08-20 10:40:18 -05:00

30 lines
961 B
C++

// This file Copyright © 2007-2022 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 "transmission.h"
#include "block-info.h"
#include "tr-assert.h"
void tr_block_info::initSizes(uint64_t total_size_in, uint32_t 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;
}