mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-31 00:05:13 +02:00
refactor: use _MiB consistently for Mebibyte conversions
Replace hard-coded MiB byte conversions (e.g. `1024*1024`, `1<<20`, `1048576`) with the existing `_MiB` literal to improve readability and avoid repeating constants.
In the few spots where arithmetic involves signed values, the result is identical to the previous code assuming those quantities never turn negative.
Also switch to brace init on every declaration assigned from `_MiB`/`_GiB` literals so a future oversized value (e.g. `unsigned int x{4096_MiB}`) becomes a compile error through the C++11 narrowing check instead of silently truncating.
Extend unit tests to cover the 32-bit `size_t` overflow boundary and to assert equivalence for integer and floating-point conversions.
Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Co-authored-by: w0xlt <94266259+w0xlt@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <crypto/chacha20.h>
|
||||
#include <crypto/chacha20poly1305.h>
|
||||
#include <span.h>
|
||||
#include <util/byte_units.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -15,7 +16,7 @@
|
||||
/* Number of bytes to process per iteration */
|
||||
static const uint64_t BUFFER_SIZE_TINY = 64;
|
||||
static const uint64_t BUFFER_SIZE_SMALL = 256;
|
||||
static const uint64_t BUFFER_SIZE_LARGE = 1024*1024;
|
||||
static const uint64_t BUFFER_SIZE_LARGE{1_MiB};
|
||||
|
||||
static void CHACHA20(benchmark::Bench& bench, size_t buffersize)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <util/byte_units.h>
|
||||
#include <vector>
|
||||
|
||||
#define ASIZE 2048
|
||||
@@ -15,7 +16,7 @@
|
||||
static void BenchLockedPool(benchmark::Bench& bench)
|
||||
{
|
||||
void *synth_base = reinterpret_cast<void*>(0x08000000);
|
||||
const size_t synth_size = 1024*1024;
|
||||
const size_t synth_size{1_MiB};
|
||||
Arena b(synth_base, synth_size, 16);
|
||||
|
||||
std::vector<void*> addr{ASIZE, nullptr};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <bench/bench.h>
|
||||
#include <crypto/poly1305.h>
|
||||
#include <span.h>
|
||||
#include <util/byte_units.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -14,7 +15,7 @@
|
||||
/* Number of bytes to process per iteration */
|
||||
static constexpr uint64_t BUFFER_SIZE_TINY = 64;
|
||||
static constexpr uint64_t BUFFER_SIZE_SMALL = 256;
|
||||
static constexpr uint64_t BUFFER_SIZE_LARGE = 1024*1024;
|
||||
static constexpr uint64_t BUFFER_SIZE_LARGE{1_MiB};
|
||||
|
||||
static void POLY1305(benchmark::Bench& bench, size_t buffersize)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user