From 65a21af449bcc321e0b61690975c6206f86bc55d Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 2 Apr 2024 15:36:12 +0200 Subject: [PATCH] fixup! Introduce `BaseFileReader::get_mmap_buffer`. --- src/file_reader.cpp | 12 ++++++++---- src/file_reader.h | 8 -------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/file_reader.cpp b/src/file_reader.cpp index 63959ba8..0ca1caa2 100644 --- a/src/file_reader.cpp +++ b/src/file_reader.cpp @@ -199,8 +199,8 @@ const Buffer BaseFileReader::get_buffer(offset_t offset, zsize_t size) const { } } -#ifdef ENABLE_USE_MMAP const Buffer MultiPartFileReader::get_mmap_buffer(offset_t offset, zsize_t size) const { +#ifdef ENABLE_USE_MMAP auto found_range = source->locate(_offset + offset, size); auto first_part_containing_it = found_range.first; if (++first_part_containing_it != found_range.second) { @@ -215,8 +215,10 @@ const Buffer MultiPartFileReader::get_mmap_buffer(offset_t offset, zsize_t size) int fd = part->fhandle().getNativeHandle(); auto physical_local_offset = logical_local_offset + part->offset(); return Buffer::makeBuffer(makeMmappedBuffer(fd, physical_local_offset, size), size); -} +#else + return Buffer::makeBuffer(size); // unreachable #endif +} bool Reader::can_read(offset_t offset, zsize_t size) const { @@ -281,13 +283,15 @@ void FileReader::read(char* dest, offset_t offset, zsize_t size) const }; } -#ifdef ENABLE_USE_MMAP const Buffer FileReader::get_mmap_buffer(offset_t offset, zsize_t size) const { +#ifdef ENABLE_USE_MMAP auto local_offset = offset + _offset; int fd = _fhandle->getNativeHandle(); return Buffer::makeBuffer(makeMmappedBuffer(fd, local_offset, size), size); -} +#else + return Buffer::makeBuffer(size); // unreachable #endif +} std::unique_ptr FileReader::sub_reader(offset_t offset, zsize_t size) const diff --git a/src/file_reader.h b/src/file_reader.h index 285ceb69..ae366c76 100644 --- a/src/file_reader.h +++ b/src/file_reader.h @@ -36,10 +36,8 @@ class BaseFileReader : public Reader { zsize_t size() const { return _size; }; offset_t offset() const { return _offset; }; -#ifdef ENABLE_USE_MMAP virtual const Buffer get_mmap_buffer(offset_t offset, zsize_t size) const = 0; -#endif const Buffer get_buffer(offset_t offset, zsize_t size) const; protected: // data @@ -58,10 +56,7 @@ class FileReader : public BaseFileReader { char read(offset_t offset) const; void read(char *dest, offset_t offset, zsize_t size) const; -#ifdef ENABLE_USE_MMAP const Buffer get_mmap_buffer(offset_t offset, zsize_t size) const; -#endif - std::unique_ptr sub_reader(offset_t offset, zsize_t size) const; private: // data @@ -79,10 +74,7 @@ class MultiPartFileReader : public BaseFileReader { char read(offset_t offset) const; void read(char *dest, offset_t offset, zsize_t size) const; -#ifdef ENABLE_USE_MMAP const Buffer get_mmap_buffer(offset_t offset, zsize_t size) const; -#endif - std::unique_ptr sub_reader(offset_t offset, zsize_t size) const; private: