break;
case ConfigItem::compression_level:
- m_compression_level = util::value_or_throw<core::Error>(
- util::parse_signed(value, INT8_MIN, INT8_MAX, "compression_level"));
+ m_compression_level = static_cast<int8_t>(util::value_or_throw<core::Error>(
+ util::parse_signed(value, INT8_MIN, INT8_MAX, "compression_level")));
break;
case ConfigItem::cpp_extension:
break;
case ConfigItem::debug_level:
- m_debug_level = util::value_or_throw<core::Error>(
- util::parse_unsigned(value, std::nullopt, std::nullopt, "debug level"));
+ m_debug_level = static_cast<uint8_t>(util::value_or_throw<core::Error>(
+ util::parse_unsigned(value, 0, UINT8_MAX, "debug level")));
break;
case ConfigItem::depend_mode:
PRINT(stdout, "\r{} {:5.1f}%", m_header, new_value_percent);
} else {
size_t total_bar_width = m_width - first_part_width;
- size_t filled_bar_width = (new_value_percent / 100) * total_bar_width;
+ size_t filled_bar_width = static_cast<size_t>(
+ (new_value_percent / 100) * static_cast<double>(total_bar_width));
size_t unfilled_bar_width = total_bar_width - filled_bar_width;
PRINT(stdout,
"\r{} {:5.1f}% [{:=<{}}{: <{}}]",
return std::nullopt;
}
- // Ignore clang -ivfsoverlay <arg> to not detect multiple input files.
if (arg == "-ivfsoverlay"
&& !(config.sloppiness().contains(core::Sloppy::ivfsoverlay))) {
LOG_RAW(
"You have to specify \"ivfsoverlay\" sloppiness when using"
" -ivfsoverlay to get hits");
+ ++i;
return Statistic::unsupported_compiler_option;
}
writer.write_int(compression_level);
writer.write_int<uint8_t>(self_contained);
writer.write_int(creation_time);
- writer.write_int<uint8_t>(ccache_version.length());
+ writer.write_int(static_cast<uint8_t>(ccache_version.length()));
writer.write_str(ccache_version);
- writer.write_int<uint8_t>(namespace_.length());
+ writer.write_int(static_cast<uint8_t>(namespace_.length()));
writer.write_str(namespace_);
writer.write_int(entry_size);
}
uint32_t
CacheEntry::Header::uncompressed_payload_size() const
{
- return entry_size - serialized_size() - k_epilogue_fields_size;
+ return static_cast<uint32_t>(entry_size - serialized_size()
+ - k_epilogue_fields_size);
}
CacheEntry::CacheEntry(nonstd::span<const uint8_t> data) : m_header(data)
file_info_indexes.reserve(included_files.size());
for (const auto& [path, digest] : included_files) {
- file_info_indexes.push_back(get_file_info_index(
- path, digest, mf_files, mf_file_infos, stat_file_function));
+ auto index = get_file_info_index(
+ path, digest, mf_files, mf_file_infos, stat_file_function);
+ if (!index) {
+ LOG_RAW("Index overflow in manifest");
+ return false;
+ }
+ file_info_indexes.push_back(*index);
}
ResultEntry entry{std::move(file_info_indexes), result_key};
throw core::Error(
FMT("Serialized manifest too large ({} > {})", size, max));
}
- return size;
+ return static_cast<uint32_t>(size);
}
void
core::CacheEntryDataWriter writer(output);
writer.write_int(k_format_version);
- writer.write_int<uint32_t>(m_files.size());
+ writer.write_int(static_cast<uint32_t>(m_files.size()));
for (const auto& file : m_files) {
- writer.write_int<uint16_t>(file.length());
+ writer.write_int(static_cast<uint16_t>(file.length()));
writer.write_str(file);
}
- writer.write_int<uint32_t>(m_file_infos.size());
+ writer.write_int(static_cast<uint32_t>(m_file_infos.size()));
for (const auto& file_info : m_file_infos) {
writer.write_int<uint32_t>(file_info.index);
writer.write_bytes(file_info.digest);
writer.write_int(file_info.ctime.nsec());
}
- writer.write_int<uint32_t>(m_results.size());
+ writer.write_int(static_cast<uint32_t>(m_results.size()));
for (const auto& result : m_results) {
- writer.write_int<uint32_t>(result.file_info_indexes.size());
+ writer.write_int(static_cast<uint32_t>(result.file_info_indexes.size()));
for (auto index : result.file_info_indexes) {
writer.write_int(index);
}
m_results.clear();
}
-uint32_t
+std::optional<uint32_t>
Manifest::get_file_info_index(
const std::string& path,
const Hash::Digest& digest,
const auto f_it = mf_files.find(path);
if (f_it != mf_files.end()) {
fi.index = f_it->second;
+ } else if (m_files.size() > UINT32_MAX) {
+ return std::nullopt;
} else {
m_files.push_back(path);
- fi.index = m_files.size() - 1;
+ fi.index = static_cast<uint32_t>(m_files.size() - 1);
}
fi.digest = digest;
const auto fi_it = mf_file_infos.find(fi);
if (fi_it != mf_file_infos.end()) {
return fi_it->second;
+ } else if (m_file_infos.size() > UINT32_MAX) {
+ return std::nullopt;
} else {
m_file_infos.push_back(fi);
return m_file_infos.size() - 1;
void clear();
- uint32_t get_file_info_index(
+ std::optional<uint32_t> get_file_info_index(
const std::string& path,
const Hash::Digest& digest,
const std::unordered_map<std::string, uint32_t>& mf_files,
throw Error(
FMT("Serialized result too large ({} > {})", m_serialized_size, max));
}
- return m_serialized_size;
+ return static_cast<uint32_t>(m_serialized_size);
}
void
CacheEntryDataWriter writer(output);
writer.write_int(k_format_version);
- writer.write_int<uint8_t>(m_file_entries.size());
+ writer.write_int(static_cast<uint8_t>(m_file_entries.size()));
uint8_t file_number = 0;
for (const auto& entry : m_file_entries) {
return "";
}
- std::string result = FMT("({:5.2f}%)", (100.0 * nominator) / denominator);
+ std::string result = FMT("({:5.2f}%)",
+ (100.0 * static_cast<double>(nominator))
+ / static_cast<double>(denominator));
if (result.length() <= 8) {
return result;
} else {
- return FMT("({:5.1f}%)", (100.0 * nominator) / denominator);
+ return FMT("({:5.1f}%)",
+ (100.0 * static_cast<double>(nominator))
+ / static_cast<double>(denominator));
}
}
table.add_heading("Local storage:");
}
if (!from_log) {
- std::vector<C> size_cells{
- FMT(" Cache size ({}):", size_unit),
- C(FMT("{:.1f}", static_cast<double>(local_size) / size_divider))
- .right_align()};
+ std::vector<C> size_cells{FMT(" Cache size ({}):", size_unit),
+ C(FMT("{:.1f}",
+ static_cast<double>(local_size)
+ / static_cast<double>(size_divider)))
+ .right_align()};
if (config.max_size() != 0) {
size_cells.emplace_back("/");
- size_cells.emplace_back(
- C(FMT("{:.1f}", static_cast<double>(config.max_size()) / size_divider))
- .right_align());
+ size_cells.emplace_back(C(FMT("{:.1f}",
+ static_cast<double>(config.max_size())
+ / static_cast<double>(size_divider)))
+ .right_align());
size_cells.emplace_back(percent(local_size, config.max_size()));
}
table.add_row(size_cells);
const storage::local::CompressionStatistics& cs)
{
const double ratio = cs.actual_size > 0
- ? static_cast<double>(cs.content_size) / cs.actual_size
+ ? static_cast<double>(cs.content_size)
+ / static_cast<double>(cs.actual_size)
: 0.0;
const double savings = ratio > 0.0 ? 100.0 - (100.0 / ratio) : 0.0;
break;
case RECOMPRESS_THREADS:
- recompress_threads = util::value_or_throw<Error>(util::parse_unsigned(
- arg, 1, std::numeric_limits<uint32_t>::max(), "threads"));
+ recompress_threads =
+ static_cast<uint32_t>(util::value_or_throw<Error>(util::parse_unsigned(
+ arg, 1, std::numeric_limits<uint32_t>::max(), "threads")));
break;
case TRIM_MAX_SIZE: {
case TRIM_RECOMPRESS_THREADS:
trim_recompress_threads =
- util::value_or_throw<Error>(util::parse_unsigned(
- arg, 1, std::numeric_limits<uint32_t>::max(), "threads"));
+ static_cast<uint32_t>(util::value_or_throw<Error>(util::parse_unsigned(
+ arg, 1, std::numeric_limits<uint32_t>::max(), "threads")));
break;
case 'v': // --verbose
Level2Counters after;
};
+template<typename T>
+static double
+ratio(T numerator, T denominator)
+{
+ if (denominator == 0) {
+ return 0.0;
+ } else {
+ return static_cast<double>(numerator) / static_cast<double>(denominator);
+ }
+}
+
static CleanDirResult
clean_dir(
const std::string& l2_dir,
raw_files_map;
for (size_t i = 0; i < files.size();
- ++i, progress_receiver(1.0 / 3 + 1.0 * i / files.size() / 3)) {
+ ++i, progress_receiver(1.0 / 3 + 1.0 * ratio(i, files.size()) / 3)) {
const auto& file = files[i];
if (!file.is_regular_file()) {
bool cleaned = false;
for (size_t i = 0; i < files.size();
- ++i, progress_receiver(2.0 / 3 + 1.0 * i / files.size() / 3)) {
+ ++i, progress_receiver(2.0 / 3 + 1.0 * ratio(i, files.size()) / 3)) {
const auto& file = files[i];
if (!file || file.is_directory()) {
// Pseudo-randomly choose one of the stats files in the 256 level 2
// directories.
const auto bucket = getpid() % 256;
- const uint8_t l1_index = bucket / 16;
- const uint8_t l2_index = bucket % 16;
+ const uint8_t l1_index = static_cast<uint8_t>(bucket / 16);
+ const uint8_t l2_index = static_cast<uint8_t>(bucket % 16);
const auto l2_stats_file = get_stats_file(l1_index, l2_index);
uint64_t l2_files_in_cache = 0;
for (size_t i = 0; i < files.size(); ++i) {
util::remove_nfs_safe(files[i].path().string());
- l2_progress_receiver(0.5 + 0.5 * i / files.size());
+ l2_progress_receiver(0.5 + 0.5 * ratio(i, files.size()));
}
if (!files.empty()) {
} catch (core::Error&) {
cs.incompressible_size += cache_file.size_on_disk();
}
- l2_progress_receiver(0.2 + 0.8 * i / files.size());
+ l2_progress_receiver(0.2 + 0.8 * ratio(i, files.size()));
}
});
});
incompressible_size += file.size_on_disk();
}
- l2_progress_receiver(0.1 + 0.9 * i / files.size());
+ l2_progress_receiver(0.1 + 0.9 * ratio(i, files.size()));
}
if (util::ends_with(l2_dir, "f/f")) {
PRINT_RAW(stdout, "\n\n");
}
- const double old_ratio = recompressor.old_size() > 0
- ? static_cast<double>(recompressor.content_size())
- / recompressor.old_size()
- : 0.0;
+ const double old_ratio =
+ ratio(recompressor.content_size(), recompressor.old_size());
const double old_savings =
old_ratio > 0.0 ? 100.0 - (100.0 / old_ratio) : 0.0;
- const double new_ratio = recompressor.new_size() > 0
- ? static_cast<double>(recompressor.content_size())
- / recompressor.new_size()
- : 0.0;
+ const double new_ratio =
+ ratio(recompressor.content_size(), recompressor.new_size());
const double new_savings =
new_ratio > 0.0 ? 100.0 - (100.0 / new_ratio) : 0.0;
const int64_t size_diff = static_cast<int64_t>(recompressor.new_size())
// practice removing much newer entries than the oldest in other
// subdirectories. By doing cleanup based on the number of files, both example
// scenarios are improved.
- const uint64_t target_files = 0.9 * evaluation->total_files / 256;
+ const uint64_t target_files = static_cast<uint64_t>(
+ 0.9 * static_cast<double>(evaluation->total_files) / 256);
auto clean_dir_result = clean_dir(
get_subdir(evaluation->l1_index, largest_level_2_index), 0, target_files);
}
}
- connect(url, connect_timeout.count(), operation_timeout.count());
+ connect(url,
+ static_cast<uint32_t>(connect_timeout.count()),
+ static_cast<uint32_t>(operation_timeout.count()));
authenticate(url);
select_database(url);
}
} else {
const std::string host = url.host().empty() ? "localhost" : url.host();
const uint32_t port =
- url.port().empty() ? DEFAULT_PORT
- : util::value_or_throw<core::Fatal>(
- util::parse_unsigned(url.port(), 1, 65535, "port"));
+ url.port().empty()
+ ? DEFAULT_PORT
+ : static_cast<uint32_t>(util::value_or_throw<core::Fatal>(
+ util::parse_unsigned(url.port(), 1, 65535, "port")));
ASSERT(url.path().empty() || url.path()[0] == '/');
LOG("Redis connecting to {}:{} (connect timeout {} ms)",
}
const uint32_t db_number =
!db ? 0
- : util::value_or_throw<core::Fatal>(util::parse_unsigned(
- *db, 0, std::numeric_limits<uint32_t>::max(), "db number"));
+ : static_cast<uint32_t>(
+ util::value_or_throw<core::Fatal>(util::parse_unsigned(
+ *db, 0, std::numeric_limits<uint32_t>::max(), "db number")));
if (db_number != 0) {
LOG("Redis SELECT {}", db_number);
-// Copyright (C) 2022 Joel Rosdahl and other contributors
+// Copyright (C) 2022-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
inline Duration
Duration::operator*(double factor) const
{
- return Duration(0, factor * m_ns);
+ return Duration(0, static_cast<int64_t>(factor * static_cast<double>(m_ns)));
}
inline Duration
Duration::operator/(double factor) const
{
- return Duration(0, m_ns / factor);
+ return Duration(0, static_cast<int64_t>(static_cast<double>(m_ns) / factor));
}
inline int64_t
inline int32_t
Duration::nsec_decimal_part() const
{
- return m_ns % 1'000'000'000;
+ return static_cast<int32_t>(m_ns % 1'000'000'000);
}
} // namespace util
#include <random>
#include <sstream>
-// Seconds.
-const double k_min_sleep_time = 0.010;
-const double k_max_sleep_time = 0.050;
+const uint32_t k_min_sleep_time_ms = 100;
+const uint32_t k_max_sleep_time_ms = 500;
#ifndef _WIN32
const util::Duration k_staleness_limit(2);
#endif
}();
std::string initial_content;
- RandomNumberGenerator sleep_ms_generator(k_min_sleep_time * 1000,
- k_max_sleep_time * 1000);
+ RandomNumberGenerator sleep_ms_generator(k_min_sleep_time_ms,
+ k_max_sleep_time_ms);
while (true) {
const auto now = TimePoint::now();
LockFile::do_acquire(const bool blocking)
{
void* handle;
- RandomNumberGenerator sleep_ms_generator(k_min_sleep_time * 1000,
- k_max_sleep_time * 1000);
+ RandomNumberGenerator sleep_ms_generator(k_min_sleep_time_ms,
+ k_max_sleep_time_ms);
while (true) {
DWORD flags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE;
// [1]: <https://github.com/Alexpux/mingw-w64/blob/
// d0d7f784833bbb0b2d279310ddc6afb52fe47a46/mingw-w64-crt/misc/mkstemp.c>
- Fd fd(bsd_mkstemps(&path_template[0], suffix.length()));
+ Fd fd(bsd_mkstemps(&path_template[0], static_cast<int>(suffix.length())));
#else
- Fd fd(mkstemps(&path_template[0], suffix.length()));
+ Fd fd(mkstemps(&path_template[0], static_cast<int>(suffix.length())));
#endif
if (!fd) {
return tl::unexpected(FMT("failed to create temporary file for {}: {}",
inline int32_t
TimePoint::nsec_decimal_part() const
{
- return m_ns % 1'000'000'000;
+ return static_cast<int32_t>(m_ns % 1'000'000'000);
}
inline void
int_to_big_endian(T value, uint8_t* buffer)
{
for (size_t i = 0; i < sizeof(T); ++i) {
- buffer[sizeof(T) - i - 1] = value & 0xFF;
+ buffer[sizeof(T) - i - 1] = static_cast<uint8_t>(value & 0xFF);
value >>= 8;
}
}
format_human_readable_size(uint64_t size, SizeUnitPrefixType prefix_type)
{
const double factor = prefix_type == SizeUnitPrefixType::binary ? 1024 : 1000;
+ const double dsize = static_cast<double>(size);
const char* infix = prefix_type == SizeUnitPrefixType::binary ? "i" : "";
- if (size >= factor * factor * factor) {
- return FMT("{:.1f} G{}B", size / (factor * factor * factor), infix);
- } else if (size >= factor * factor) {
- return FMT("{:.1f} M{}B", size / (factor * factor), infix);
- } else if (size >= factor) {
+ if (dsize >= factor * factor * factor) {
+ return FMT("{:.1f} G{}B", dsize / (factor * factor * factor), infix);
+ } else if (dsize >= factor * factor) {
+ return FMT("{:.1f} M{}B", dsize / (factor * factor), infix);
+ } else if (dsize >= factor) {
const char* k = prefix_type == SizeUnitPrefixType::binary ? "K" : "k";
- return FMT("{:.1f} {}{}B", size / factor, k, infix);
+ return FMT("{:.1f} {}{}B", dsize / factor, k, infix);
} else if (size == 1) {
return "1 byte";
} else {
tl::expected<mode_t, std::string>
parse_umask(std::string_view value)
{
- return parse_unsigned(value, 0, 0777, "umask", 8);
+ auto result = parse_unsigned(value, 0, 0777, "umask", 8);
+ if (result) {
+ return static_cast<mode_t>(*result);
+ } else {
+ return tl::unexpected(result.error());
+ }
}
tl::expected<uint64_t, std::string>
return {1, "minimum level supported by libzstd"};
}
- const int8_t level = std::min<int>(wanted_level, ZSTD_maxCLevel());
+ const int8_t level =
+ static_cast<int8_t>(std::min<int>(wanted_level, ZSTD_maxCLevel()));
if (level != wanted_level) {
return {level, "max libzstd level"};
}
const auto res =
util::split_into_views(input, separators, m_mode, m_include_delimiter);
REQUIRE(res.size() == expected.size());
- for (int i = 0, total = expected.size(); i < total; ++i) {
+ for (size_t i = 0, total = expected.size(); i < total; ++i) {
CHECK(res[i] == expected[i]);
}
}
std::vector<uint8_t> expected;
for (size_t i = 0; i < 512; ++i) {
- expected.push_back((32 + i) % 256);
+ expected.push_back(static_cast<uint8_t>((32 + i) % 256));
}
CHECK(util::write_file("test", expected));
CHECK(util::format_human_readable_diff(0, SUPT::binary) == "0 bytes");
CHECK(util::format_human_readable_diff(1, SUPT::binary) == "+1 byte");
CHECK(util::format_human_readable_diff(42, SUPT::binary) == "+42 bytes");
- CHECK(util::format_human_readable_diff(1949, SUPT::binary) == "+1.9 KiB");
- CHECK(util::format_human_readable_diff(1951, SUPT::binary) == "+1.9 KiB");
- CHECK(util::format_human_readable_diff(499.7 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(1'949, SUPT::binary) == "+1.9 KiB");
+ CHECK(util::format_human_readable_diff(1'951, SUPT::binary) == "+1.9 KiB");
+ CHECK(util::format_human_readable_diff(499'700, SUPT::binary)
== "+488.0 KiB");
- CHECK(util::format_human_readable_diff(1000 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(1'000'000, SUPT::binary)
== "+976.6 KiB");
- CHECK(util::format_human_readable_diff(1234 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(1'234'000, SUPT::binary)
== "+1.2 MiB");
- CHECK(util::format_human_readable_diff(438.5 * 1000 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(438'500'000, SUPT::binary)
== "+418.2 MiB");
- CHECK(util::format_human_readable_diff(1000 * 1000 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(1'000'000'000, SUPT::binary)
== "+953.7 MiB");
- CHECK(
- util::format_human_readable_diff(17.11 * 1000 * 1000 * 1000, SUPT::binary)
- == "+15.9 GiB");
+ CHECK(util::format_human_readable_diff(17'110'000'000, SUPT::binary)
+ == "+15.9 GiB");
CHECK(util::format_human_readable_diff(-1, SUPT::binary) == "-1 byte");
CHECK(util::format_human_readable_diff(-42, SUPT::binary) == "-42 bytes");
- CHECK(util::format_human_readable_diff(-1949, SUPT::binary) == "-1.9 KiB");
- CHECK(util::format_human_readable_diff(-1951, SUPT::binary) == "-1.9 KiB");
- CHECK(util::format_human_readable_diff(-499.7 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(-1'949, SUPT::binary) == "-1.9 KiB");
+ CHECK(util::format_human_readable_diff(-1'951, SUPT::binary) == "-1.9 KiB");
+ CHECK(util::format_human_readable_diff(-499'700, SUPT::binary)
== "-488.0 KiB");
- CHECK(util::format_human_readable_diff(-1000 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(-1'000'000, SUPT::binary)
== "-976.6 KiB");
- CHECK(util::format_human_readable_diff(-1234 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(-1'234'000, SUPT::binary)
== "-1.2 MiB");
- CHECK(util::format_human_readable_diff(-438.5 * 1000 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(-438'500'000, SUPT::binary)
== "-418.2 MiB");
- CHECK(util::format_human_readable_diff(-1000 * 1000 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_diff(-1'000'000'000, SUPT::binary)
== "-953.7 MiB");
- CHECK(util::format_human_readable_diff(-17.11 * 1000 * 1000 * 1000,
- SUPT::binary)
+ CHECK(util::format_human_readable_diff(-17'110'000'000, SUPT::binary)
== "-15.9 GiB");
}
CHECK(util::format_human_readable_diff(0, SUPT::decimal) == "0 bytes");
CHECK(util::format_human_readable_diff(1, SUPT::decimal) == "+1 byte");
CHECK(util::format_human_readable_diff(42, SUPT::decimal) == "+42 bytes");
- CHECK(util::format_human_readable_diff(1949, SUPT::decimal) == "+1.9 kB");
- CHECK(util::format_human_readable_diff(1951, SUPT::decimal) == "+2.0 kB");
- CHECK(util::format_human_readable_diff(499.7 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(1'949, SUPT::decimal) == "+1.9 kB");
+ CHECK(util::format_human_readable_diff(1'951, SUPT::decimal) == "+2.0 kB");
+ CHECK(util::format_human_readable_diff(499'700, SUPT::decimal)
== "+499.7 kB");
- CHECK(util::format_human_readable_diff(1000 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(1'000'000, SUPT::decimal)
== "+1.0 MB");
- CHECK(util::format_human_readable_diff(1234 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(1'234'000, SUPT::decimal)
== "+1.2 MB");
- CHECK(util::format_human_readable_diff(438.5 * 1000 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(438'500'000, SUPT::decimal)
== "+438.5 MB");
- CHECK(util::format_human_readable_diff(1000 * 1000 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(1'000'000'000, SUPT::decimal)
== "+1.0 GB");
- CHECK(util::format_human_readable_diff(17.11 * 1000 * 1000 * 1000,
- SUPT::decimal)
+ CHECK(util::format_human_readable_diff(17'110'000'000, SUPT::decimal)
== "+17.1 GB");
CHECK(util::format_human_readable_diff(-1, SUPT::decimal) == "-1 byte");
CHECK(util::format_human_readable_diff(-42, SUPT::decimal) == "-42 bytes");
- CHECK(util::format_human_readable_diff(-1949, SUPT::decimal) == "-1.9 kB");
- CHECK(util::format_human_readable_diff(-1951, SUPT::decimal) == "-2.0 kB");
- CHECK(util::format_human_readable_diff(-499.7 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(-1'949, SUPT::decimal) == "-1.9 kB");
+ CHECK(util::format_human_readable_diff(-1'951, SUPT::decimal) == "-2.0 kB");
+ CHECK(util::format_human_readable_diff(-499'700, SUPT::decimal)
== "-499.7 kB");
- CHECK(util::format_human_readable_diff(-1000 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(-1'000'000, SUPT::decimal)
== "-1.0 MB");
- CHECK(util::format_human_readable_diff(-1234 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(-1'234'000, SUPT::decimal)
== "-1.2 MB");
- CHECK(util::format_human_readable_diff(-438.5 * 1000 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(-438'500'000, SUPT::decimal)
== "-438.5 MB");
- CHECK(util::format_human_readable_diff(-1000 * 1000 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_diff(-1'000'000'000, SUPT::decimal)
== "-1.0 GB");
- CHECK(util::format_human_readable_diff(-17.11 * 1000 * 1000 * 1000,
- SUPT::decimal)
+ CHECK(util::format_human_readable_diff(-17'110'000'000, SUPT::decimal)
== "-17.1 GB");
}
}
CHECK(util::format_human_readable_size(0, SUPT::binary) == "0 bytes");
CHECK(util::format_human_readable_size(1, SUPT::binary) == "1 byte");
CHECK(util::format_human_readable_size(42, SUPT::binary) == "42 bytes");
- CHECK(util::format_human_readable_size(1949, SUPT::binary) == "1.9 KiB");
- CHECK(util::format_human_readable_size(1951, SUPT::binary) == "1.9 KiB");
- CHECK(util::format_human_readable_size(499.7 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_size(1'949, SUPT::binary) == "1.9 KiB");
+ CHECK(util::format_human_readable_size(1'951, SUPT::binary) == "1.9 KiB");
+ CHECK(util::format_human_readable_size(499'700, SUPT::binary)
== "488.0 KiB");
- CHECK(util::format_human_readable_size(1000 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_size(1'000'000, SUPT::binary)
== "976.6 KiB");
- CHECK(util::format_human_readable_size(1234 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_size(1'234'000, SUPT::binary)
== "1.2 MiB");
- CHECK(util::format_human_readable_size(438.5 * 1000 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_size(438'500'000, SUPT::binary)
== "418.2 MiB");
- CHECK(util::format_human_readable_size(1000 * 1000 * 1000, SUPT::binary)
+ CHECK(util::format_human_readable_size(1'000'000'000, SUPT::binary)
== "953.7 MiB");
- CHECK(
- util::format_human_readable_size(17.11 * 1000 * 1000 * 1000, SUPT::binary)
- == "15.9 GiB");
+ CHECK(util::format_human_readable_size(17'110'000'000, SUPT::binary)
+ == "15.9 GiB");
}
SUBCASE("decimal")
CHECK(util::format_human_readable_size(0, SUPT::decimal) == "0 bytes");
CHECK(util::format_human_readable_size(1, SUPT::decimal) == "1 byte");
CHECK(util::format_human_readable_size(42, SUPT::decimal) == "42 bytes");
- CHECK(util::format_human_readable_size(1949, SUPT::decimal) == "1.9 kB");
- CHECK(util::format_human_readable_size(1951, SUPT::decimal) == "2.0 kB");
- CHECK(util::format_human_readable_size(499.7 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_size(1'949, SUPT::decimal) == "1.9 kB");
+ CHECK(util::format_human_readable_size(1'951, SUPT::decimal) == "2.0 kB");
+ CHECK(util::format_human_readable_size(499'700, SUPT::decimal)
== "499.7 kB");
- CHECK(util::format_human_readable_size(1000 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_size(1'000'000, SUPT::decimal)
== "1.0 MB");
- CHECK(util::format_human_readable_size(1234 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_size(1'234'000, SUPT::decimal)
== "1.2 MB");
- CHECK(util::format_human_readable_size(438.5 * 1000 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_size(438'500'000, SUPT::decimal)
== "438.5 MB");
- CHECK(util::format_human_readable_size(1000 * 1000 * 1000, SUPT::decimal)
+ CHECK(util::format_human_readable_size(1'000'000'000, SUPT::decimal)
== "1.0 GB");
- CHECK(util::format_human_readable_size(17.11 * 1000 * 1000 * 1000,
- SUPT::decimal)
+ CHECK(util::format_human_readable_size(17'110'000'000, SUPT::decimal)
== "17.1 GB");
}
}
== h(u64(42) * 1024 * 1024 * 1024, SUPT::binary));
// Decimal suffixes
- CHECK(*util::parse_size("78k") == h(78 * 1000, SUPT::decimal));
- CHECK(*util::parse_size("78K") == h(78 * 1000, SUPT::decimal));
- CHECK(*util::parse_size("1.1 M") == h(u64(1.1 * 1000 * 1000), SUPT::decimal));
+ CHECK(*util::parse_size("78k") == h(78'000, SUPT::decimal));
+ CHECK(*util::parse_size("78K") == h(78'000, SUPT::decimal));
+ CHECK(*util::parse_size("1.1 M") == h(u64(1.1 * 1'000'000), SUPT::decimal));
CHECK(*util::parse_size("438.55M")
- == h(u64(438.55 * 1000 * 1000), SUPT::decimal));
- CHECK(*util::parse_size("1 G") == h(1 * 1000 * 1000 * 1000, SUPT::decimal));
+ == h(u64(438.55 * 1'000'000), SUPT::decimal));
+ CHECK(*util::parse_size("1 G") == h(1 * 1'000'000'000, SUPT::decimal));
CHECK(*util::parse_size("2T")
- == h(u64(2) * 1000 * 1000 * 1000 * 1000, SUPT::decimal));
+ == h(u64(2) * 1'000'000 * 1'000'000, SUPT::decimal));
// Binary suffixes
CHECK(*util::parse_size("78 Ki") == h(78 * 1024, SUPT::binary));
== h(u64(2) * 1024 * 1024 * 1024 * 1024, SUPT::binary));
// With B suffix
- CHECK(*util::parse_size("9MB") == h(9 * 1000 * 1000, SUPT::decimal));
+ CHECK(*util::parse_size("9MB") == h(9 * 1'000'000, SUPT::decimal));
CHECK(*util::parse_size("9MiB") == h(9 * 1024 * 1024, SUPT::binary));
// Errors