Skip to content

Commit

Permalink
lib: advise the OS to not expect any more access
Browse files Browse the repository at this point in the history
  • Loading branch information
R1kaB3rN committed Dec 14, 2024
1 parent 98ddc05 commit 91c1dc4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bzip2::read::BzDecoder;
use crc32fast::Hasher;
use memmap2::{Advice, Mmap, MmapMut};
use memmap2::{Mmap, MmapMut, UncheckedAdvice};
use pyo3::prelude::*;
use qbsdiff::Bspatch;
use std::fs::File;
Expand Down Expand Up @@ -62,8 +62,12 @@ fn bspatch_rs(py: Python<'_>, source: i32, patch: &[u8]) -> io::Result<Vec<u8>>
if target.len() < original_size as usize {
let file = unsafe { File::from_raw_fd(source) };
file.set_len(target.len() as u64)?;
mmap.unchecked_advise_range(UncheckedAdvice::DontNeed, 0, target.len())?;
std::mem::forget(file);
return Ok(target);
}

mmap.unchecked_advise_range(UncheckedAdvice::DontNeed, 0, target.len())?;
Ok(target)
})
}
Expand Down

0 comments on commit 91c1dc4

Please sign in to comment.