From eedbed42d6733444d48314653f40cf61df8dd0d5 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Fri, 26 May 2023 13:52:44 +0200 Subject: [PATCH] folly::Range -> std::span in filesystem_v2 / mmif --- include/dwarfs/filesystem_v2.h | 12 ++++++++---- include/dwarfs/mmif.h | 7 +++---- src/dwarfs/filesystem_v2.cpp | 21 ++++++++++----------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/include/dwarfs/filesystem_v2.h b/include/dwarfs/filesystem_v2.h index 9239a6e9..804b5877 100644 --- a/include/dwarfs/filesystem_v2.h +++ b/include/dwarfs/filesystem_v2.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -70,9 +71,10 @@ class filesystem_v2 { int detail_level = 0, size_t num_readers = 1, bool check_integrity = false, off_t image_offset = 0); - static std::optional header(std::shared_ptr mm); + static std::optional> + header(std::shared_ptr mm); - static std::optional + static std::optional> header(std::shared_ptr mm, off_t image_offset); void dump(std::ostream& os, int detail_level) const { @@ -150,7 +152,9 @@ class filesystem_v2 { return impl_->readv(inode, size, offset); } - std::optional header() const { return impl_->header(); } + std::optional> header() const { + return impl_->header(); + } void set_num_workers(size_t num) { return impl_->set_num_workers(num); } void set_cache_tidy_config(cache_tidy_config const& cfg) { @@ -190,7 +194,7 @@ class filesystem_v2 { off_t offset) const = 0; virtual folly::Expected>, int> readv(uint32_t inode, size_t size, off_t offset) const = 0; - virtual std::optional header() const = 0; + virtual std::optional> header() const = 0; virtual void set_num_workers(size_t num) = 0; virtual void set_cache_tidy_config(cache_tidy_config const& cfg) = 0; }; diff --git a/include/dwarfs/mmif.h b/include/dwarfs/mmif.h index fb243ba7..8e121dde 100644 --- a/include/dwarfs/mmif.h +++ b/include/dwarfs/mmif.h @@ -21,13 +21,12 @@ #pragma once +#include #include #include #include -#include - namespace dwarfs { class mmif : public boost::noncopyable { @@ -40,8 +39,8 @@ class mmif : public boost::noncopyable { reinterpret_cast(this->addr()) + offset); } - folly::ByteRange range(off_t offset, size_t length) const { - return folly::ByteRange(this->as(offset), length); + std::span span(off_t offset, size_t length) const { + return std::span(this->as(offset), length); } virtual void const* addr() const = 0; diff --git a/src/dwarfs/filesystem_v2.cpp b/src/dwarfs/filesystem_v2.cpp index 06032948..498af1b8 100644 --- a/src/dwarfs/filesystem_v2.cpp +++ b/src/dwarfs/filesystem_v2.cpp @@ -28,8 +28,6 @@ #include #include -#include - #include #include "dwarfs/block_cache.h" @@ -180,11 +178,11 @@ class filesystem_parser { return std::nullopt; } - std::optional header() const { + std::optional> header() const { if (image_offset_ == 0) { return std::nullopt; } - return folly::ByteRange(mm_->as(), image_offset_); + return mm_->span(0, image_offset_); } void rewind() { @@ -250,7 +248,7 @@ get_uncompressed_section_size(std::shared_ptr mm, fs_section const& sec) { return bd.uncompressed_size(); } -folly::ByteRange +std::span get_section_data(std::shared_ptr mm, fs_section const& section, std::vector& buffer, bool force_buffer) { auto compression = section.compression(); @@ -258,7 +256,7 @@ get_section_data(std::shared_ptr mm, fs_section const& section, auto length = section.length(); if (!force_buffer && compression == compression_type::NONE) { - return mm->range(start, length); + return mm->span(start, length); } buffer = block_decompressor::decompress(compression, mm->as(start), @@ -346,7 +344,7 @@ class filesystem_ final : public filesystem_v2::impl { off_t offset) const override; folly::Expected>, int> readv(uint32_t inode, size_t size, off_t offset) const override; - std::optional header() const override; + std::optional> header() const override; void set_num_workers(size_t num) override { ir_.set_num_workers(num); } void set_cache_tidy_config(cache_tidy_config const& cfg) override { ir_.set_cache_tidy_config(cfg); @@ -362,7 +360,7 @@ class filesystem_ final : public filesystem_v2::impl { mutable std::mutex mx_; mutable filesystem_parser parser_; std::vector meta_buffer_; - std::optional header_; + std::optional> header_; mutable std::unique_ptr fsinfo_; }; @@ -575,7 +573,8 @@ filesystem_::readv(uint32_t inode, size_t size, } template -std::optional filesystem_::header() const { +std::optional> +filesystem_::header() const { return header_; } @@ -743,12 +742,12 @@ int filesystem_v2::identify(logger& lgr, std::shared_ptr mm, return errors; } -std::optional +std::optional> filesystem_v2::header(std::shared_ptr mm) { return header(std::move(mm), filesystem_options::IMAGE_OFFSET_AUTO); } -std::optional +std::optional> filesystem_v2::header(std::shared_ptr mm, off_t image_offset) { return filesystem_parser(mm, image_offset).header(); }