aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2025-02-06 11:04:10 -0800
committerJack O'Connor <[email protected]>2025-02-06 11:04:10 -0800
commita12fa7b8a4131d77c35eda5c680b9307a0fc28d3 (patch)
treecc45875f8f435bee14c84ad69c2a2bf44600be40
parent96d90e67d077c4636ef6e792b82b3e11edaefbc6 (diff)
remove checks that memmap2 does internally
-rw-r--r--Cargo.toml2
-rw-r--r--src/io.rs21
2 files changed, 4 insertions, 19 deletions
diff --git a/Cargo.toml b/Cargo.toml
index f1a1337..aec25a8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,7 +10,7 @@ readme = "README.md"
edition = "2021"
[features]
-default = ["std"]
+default = ["std", "mmap"]
# The NEON implementation does not participate in dynamic feature detection,
# which is currently x86-only. If "neon" is on, NEON support is assumed. Note
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))
}
}