mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-24 03:43:18 -04:00
feat: add binary literals for readability
This commit is contained in:
parent
240abf9f56
commit
2fe1fe7650
67
include/dwarfs/binary_literals.h
Normal file
67
include/dwarfs/binary_literals.h
Normal file
@ -0,0 +1,67 @@
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/**
|
||||
* \author Marcus Holland-Moritz (github@mhxnet.de)
|
||||
* \copyright Copyright (c) Marcus Holland-Moritz
|
||||
*
|
||||
* This file is part of dwarfs.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the “Software”), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace dwarfs::binary_literals {
|
||||
|
||||
constexpr auto operator""_KiB(unsigned long long value) {
|
||||
return static_cast<uint64_t>(value) << 10;
|
||||
}
|
||||
|
||||
constexpr auto operator""_MiB(unsigned long long value) {
|
||||
return static_cast<uint64_t>(value) << 20;
|
||||
}
|
||||
|
||||
constexpr auto operator""_GiB(unsigned long long value) {
|
||||
return static_cast<uint64_t>(value) << 30;
|
||||
}
|
||||
|
||||
constexpr auto operator""_TiB(unsigned long long value) {
|
||||
return static_cast<uint64_t>(value) << 40;
|
||||
}
|
||||
|
||||
constexpr auto operator""_KiBs(unsigned long long value) {
|
||||
return static_cast<size_t>(value) << 10;
|
||||
}
|
||||
|
||||
constexpr auto operator""_MiBs(unsigned long long value) {
|
||||
return static_cast<size_t>(value) << 20;
|
||||
}
|
||||
|
||||
constexpr auto operator""_GiBs(unsigned long long value) {
|
||||
return static_cast<size_t>(value) << 30;
|
||||
}
|
||||
|
||||
constexpr auto operator""_TiBs(unsigned long long value) {
|
||||
return static_cast<size_t>(value) << 40;
|
||||
}
|
||||
|
||||
} // namespace dwarfs::binary_literals
|
@ -81,6 +81,7 @@
|
||||
#define DWARFS_FSP_COMPAT
|
||||
#endif
|
||||
|
||||
#include <dwarfs/binary_literals.h>
|
||||
#include <dwarfs/conv.h>
|
||||
#include <dwarfs/decompressor_registry.h>
|
||||
#include <dwarfs/error.h>
|
||||
@ -110,6 +111,7 @@
|
||||
namespace {
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
using namespace dwarfs::binary_literals;
|
||||
|
||||
#ifdef DWARFS_FSP_COMPAT
|
||||
using native_stat = struct ::fuse_stat;
|
||||
@ -1649,9 +1651,8 @@ int dwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
|
||||
userdata.lgr.set_threshold(opts.logopts.threshold);
|
||||
userdata.lgr.set_with_context(opts.logopts.threshold >= logger::DEBUG);
|
||||
|
||||
opts.cachesize = opts.cachesize_str
|
||||
? parse_size_with_unit(opts.cachesize_str)
|
||||
: (static_cast<size_t>(512) << 20);
|
||||
opts.cachesize =
|
||||
opts.cachesize_str ? parse_size_with_unit(opts.cachesize_str) : 512_MiB;
|
||||
opts.blocksize = opts.blocksize_str
|
||||
? parse_size_with_unit(opts.blocksize_str)
|
||||
: kDefaultBlockSize;
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include <range/v3/view/enumerate.hpp>
|
||||
#include <range/v3/view/map.hpp>
|
||||
|
||||
#include <dwarfs/binary_literals.h>
|
||||
#include <dwarfs/block_compressor.h>
|
||||
#include <dwarfs/block_compressor_parser.h>
|
||||
#include <dwarfs/checksum.h>
|
||||
@ -107,6 +108,7 @@ namespace dwarfs::tool {
|
||||
namespace {
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
using namespace dwarfs::binary_literals;
|
||||
|
||||
constexpr sorted_array_map progress_modes{
|
||||
std::pair{"none"sv, writer::console_writer::NONE},
|
||||
@ -387,8 +389,7 @@ void validate(boost::any& v, std::vector<std::string> const& values,
|
||||
|
||||
uint64_t
|
||||
compute_memory_limit(uint64_t const block_size, uint64_t const num_cpu) {
|
||||
auto const sys_mem =
|
||||
std::max(tool::sysinfo::get_total_memory(), UINT64_C(256) << 20);
|
||||
auto const sys_mem = std::max(tool::sysinfo::get_total_memory(), 256_MiB);
|
||||
auto wanted_mem = num_cpu * block_size;
|
||||
if (wanted_mem < sys_mem / 32) {
|
||||
wanted_mem *= 2;
|
||||
|
Loading…
x
Reference in New Issue
Block a user