Skip to content

Commit

Permalink
fixup! Introduce BaseFileReader::get_mmap_buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Apr 2, 2024
1 parent 671f97c commit 65a21af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 8 additions & 4 deletions src/file_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
{
Expand Down Expand Up @@ -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<const Reader>
FileReader::sub_reader(offset_t offset, zsize_t size) const
Expand Down
8 changes: 0 additions & 8 deletions src/file_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<const Reader> sub_reader(offset_t offset, zsize_t size) const;

private: // data
Expand All @@ -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<const Reader> sub_reader(offset_t offset, zsize_t size) const;

private:
Expand Down

0 comments on commit 65a21af

Please sign in to comment.