diff options
| author | Jack O'Connor <[email protected]> | 2025-02-06 11:04:10 -0800 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2025-02-06 11:04:10 -0800 |
| commit | a12fa7b8a4131d77c35eda5c680b9307a0fc28d3 (patch) | |
| tree | cc45875f8f435bee14c84ad69c2a2bf44600be40 /src | |
| parent | 96d90e67d077c4636ef6e792b82b3e11edaefbc6 (diff) | |
remove checks that memmap2 does internally
Diffstat (limited to 'src')
| -rw-r--r-- | src/io.rs | 21 |
1 files changed, 3 insertions, 18 deletions
@@ -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)) } } |
