mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 12:28:13 -04:00
refactor: use std::cmp_*
instead of static_cast
s
This commit is contained in:
parent
d11a591837
commit
a3182ae851
@ -22,6 +22,7 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
@ -115,7 +116,7 @@ filesystem_parser::filesystem_parser(std::shared_ptr<mmif> mm,
|
||||
, image_offset_{find_image_offset(*mm_, image_offset)}
|
||||
, image_size_{
|
||||
std::min<file_off_t>(image_size, mm_->size() - image_offset_)} {
|
||||
if (image_size_ < static_cast<file_off_t>(sizeof(file_header))) {
|
||||
if (std::cmp_less(image_size_, sizeof(file_header))) {
|
||||
DWARFS_THROW(runtime_error, "file too small");
|
||||
}
|
||||
|
||||
@ -146,16 +147,16 @@ filesystem_parser::filesystem_parser(std::shared_ptr<mmif> mm,
|
||||
|
||||
std::optional<fs_section> filesystem_parser::next_section() {
|
||||
if (index_.empty()) {
|
||||
if (offset_ < image_offset_ + image_size_) {
|
||||
if (std::cmp_less(offset_, image_offset_ + image_size_)) {
|
||||
auto section = fs_section(*mm_, offset_, version_);
|
||||
offset_ = section.end();
|
||||
return section;
|
||||
}
|
||||
} else {
|
||||
if (offset_ < static_cast<file_off_t>(index_.size())) {
|
||||
if (std::cmp_less(offset_, index_.size())) {
|
||||
uint64_t id = index_[offset_++];
|
||||
uint64_t offset = id & section_offset_mask;
|
||||
uint64_t next_offset = offset_ < static_cast<file_off_t>(index_.size())
|
||||
uint64_t next_offset = std::cmp_less(offset_, index_.size())
|
||||
? index_[offset_] & section_offset_mask
|
||||
: image_size_;
|
||||
return fs_section(mm_, static_cast<section_type>(id >> 48),
|
||||
@ -212,7 +213,7 @@ void filesystem_parser::find_index() {
|
||||
index_pos &= section_offset_mask;
|
||||
index_pos += image_offset_;
|
||||
|
||||
if (index_pos < static_cast<uint64_t>(image_offset_ + image_size_)) {
|
||||
if (std::cmp_less(index_pos, image_offset_ + image_size_)) {
|
||||
auto section = fs_section(*mm_, index_pos, version_);
|
||||
|
||||
if (section.check_fast(*mm_)) {
|
||||
|
@ -284,7 +284,7 @@ inode_reader_<LoggerPolicy>::read_internal(uint32_t inode, size_t const size,
|
||||
while (it < end) {
|
||||
size_t chunksize = it->size();
|
||||
|
||||
if (static_cast<size_t>(offset) < chunksize) {
|
||||
if (std::cmp_less(offset, chunksize)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -656,7 +656,7 @@ void check_chunks(global_metadata::Meta const& meta) {
|
||||
std::array<size_t, 6> check_partitioning(global_metadata::Meta const& meta) {
|
||||
std::array<size_t, 6> offsets;
|
||||
|
||||
for (int r = 0; r < static_cast<int>(offsets.size()); ++r) {
|
||||
for (int r = 0; std::cmp_less(r, offsets.size()); ++r) {
|
||||
if (auto dep = meta.dir_entries()) {
|
||||
auto pred = [r, modes = meta.modes()](auto ino) {
|
||||
return mode_rank(modes[ino.mode_index()]) < r;
|
||||
|
@ -99,7 +99,7 @@ void check_schema(std::span<uint8_t const> data) {
|
||||
}
|
||||
for (auto const& kvl : *schema.layouts()) {
|
||||
auto const& layout = kvl.second;
|
||||
if (kvl.first >= static_cast<int64_t>(schema.layouts()->size())) {
|
||||
if (std::cmp_greater_equal(kvl.first, schema.layouts()->size())) {
|
||||
DWARFS_THROW(runtime_error, "invalid layout key in schema");
|
||||
}
|
||||
if (*layout.size() < 0) {
|
||||
@ -434,8 +434,8 @@ class metadata_ final : public metadata_v2::impl {
|
||||
PERFMON_CLS_TIMER_INIT(reg_file_size)
|
||||
PERFMON_CLS_TIMER_INIT(unpack_metadata) // clang-format on
|
||||
{
|
||||
if (static_cast<int>(meta_.directories().size() - 1) !=
|
||||
symlink_inode_offset_) {
|
||||
if (std::cmp_not_equal(meta_.directories().size() - 1,
|
||||
symlink_inode_offset_)) {
|
||||
DWARFS_THROW(
|
||||
runtime_error,
|
||||
fmt::format("metadata inconsistency: number of directories ({}) does "
|
||||
@ -443,8 +443,8 @@ class metadata_ final : public metadata_v2::impl {
|
||||
meta_.directories().size() - 1, symlink_inode_offset_));
|
||||
}
|
||||
|
||||
if (static_cast<int>(meta_.symlink_table().size()) !=
|
||||
(file_inode_offset_ - symlink_inode_offset_)) {
|
||||
if (std::cmp_not_equal(meta_.symlink_table().size(),
|
||||
file_inode_offset_ - symlink_inode_offset_)) {
|
||||
DWARFS_THROW(
|
||||
runtime_error,
|
||||
fmt::format(
|
||||
@ -689,11 +689,11 @@ class metadata_ final : public metadata_v2::impl {
|
||||
inode -= unique_files_;
|
||||
|
||||
if (!shared_files_.empty()) {
|
||||
if (inode < static_cast<int>(shared_files_.size())) {
|
||||
if (std::cmp_less(inode, shared_files_.size())) {
|
||||
inode = shared_files_[inode] + unique_files_;
|
||||
}
|
||||
} else if (auto sfp = meta_.shared_files_table()) {
|
||||
if (inode < static_cast<int>(sfp->size())) {
|
||||
if (std::cmp_less(inode, sfp->size())) {
|
||||
inode = (*sfp)[inode] + unique_files_;
|
||||
}
|
||||
}
|
||||
@ -896,19 +896,19 @@ class metadata_ final : public metadata_v2::impl {
|
||||
|
||||
std::vector<uint32_t> nlinks(dev_inode_offset_ - file_inode_offset_);
|
||||
|
||||
auto add_link = [&](int index) {
|
||||
if (index >= 0 && std::cmp_less(index, nlinks.size())) {
|
||||
++nlinks[index];
|
||||
}
|
||||
};
|
||||
|
||||
if (auto de = meta_.dir_entries()) {
|
||||
for (auto e : *de) {
|
||||
int index = int(e.inode_num()) - file_inode_offset_;
|
||||
if (index >= 0 && index < int(nlinks.size())) {
|
||||
++nlinks[index];
|
||||
}
|
||||
add_link(int(e.inode_num()) - file_inode_offset_);
|
||||
}
|
||||
} else {
|
||||
for (auto e : meta_.inodes()) {
|
||||
int index = int(e.inode_v2_2()) - file_inode_offset_;
|
||||
if (index >= 0 && index < int(nlinks.size())) {
|
||||
++nlinks[index];
|
||||
}
|
||||
add_link(int(e.inode_v2_2()) - file_inode_offset_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ void categorizer_job_<LoggerPolicy>::categorize_sequential(
|
||||
|
||||
if (seq_jobs_.empty()) [[unlikely]] {
|
||||
for (auto&& [index, cat] : ranges::views::enumerate(mgr_.categorizers())) {
|
||||
if (index_ >= 0 && static_cast<int>(index) >= index_) {
|
||||
if (index_ >= 0 && std::cmp_greater_equal(index, index_)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ class inode_ : public inode {
|
||||
|
||||
for (auto [cat, size] : fragments_.get_category_sizes()) {
|
||||
if (auto max = opts.max_similarity_scan_size;
|
||||
max && static_cast<size_t>(size) > *max) {
|
||||
max && std::cmp_greater(size, *max)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user