aboutsummaryrefslogtreecommitdiff
path: root/src/io.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/io.rs')
-rw-r--r--src/io.rs21
1 files changed, 3 insertions, 18 deletions
diff --git a/src/io.rs b/src/io.rs
index 1c19881..7e8e154 100644
--- a/src/io.rs
+++ b/src/io.rs
@@ -50,30 +50,15 @@ pub(crate) fn copy_wide(
pub(crate) fn maybe_mmap_file(file: &std::fs::File) -> std::io::Result<Option<memmap2::Mmap>> {
let metadata = file.metadata()?;
let file_size = metadata.len();
- #[allow(clippy::if_same_then_else)]
if !metadata.is_file() {
// Not a real file.
Ok(None)
- } else if file_size > isize::max_value() as u64 {
- // Too long to safely map.
- // https://github.com/danburkert/memmap-rs/issues/69
- Ok(None)
- } else if file_size == 0 {
- // Mapping an empty file currently fails.
- // https://github.com/danburkert/memmap-rs/issues/72
- // See test_mmap_virtual_file.
- Ok(None)
} else if file_size < 16 * 1024 {
- // Mapping small files is not worth it.
+ // Mapping small files is not worth it, and some special files that can't be mapped report
+ // a size of zero.
Ok(None)
} else {
- // Explicitly set the length of the memory map, so that filesystem
- // changes can't race to violate the invariants we just checked.
- let map = unsafe {
- memmap2::MmapOptions::new()
- .len(file_size as usize)
- .map(file)?
- };
+ let map = unsafe { memmap2::Mmap::map(file)? };
Ok(Some(map))
}
}