diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-03-16 21:39:03 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-08-28 21:45:02 +0200 |
| commit | 4afdeaaabd021bf5ac03d74c7577747ccbb926d0 (patch) | |
| tree | c8c992d102a9c9691b6d09a5e819f200c0d987af /compiler/rustc_incremental/src | |
| parent | 05cccdc9b321e6565b3e62e8b52aec53d106ef2f (diff) | |
| download | rust-4afdeaaabd021bf5ac03d74c7577747ccbb926d0.tar.gz rust-4afdeaaabd021bf5ac03d74c7577747ccbb926d0.zip | |
Mmap the incremental data instead of reading it.
Diffstat (limited to 'compiler/rustc_incremental/src')
| -rw-r--r-- | compiler/rustc_incremental/src/persist/file_format.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_incremental/src/persist/load.rs | 3 |
2 files changed, 9 insertions, 6 deletions
diff --git a/compiler/rustc_incremental/src/persist/file_format.rs b/compiler/rustc_incremental/src/persist/file_format.rs index b821ed6cff9..501f6bdb9cf 100644 --- a/compiler/rustc_incremental/src/persist/file_format.rs +++ b/compiler/rustc_incremental/src/persist/file_format.rs @@ -14,6 +14,7 @@ use std::fs; use std::io::{self, Read}; use std::path::Path; +use rustc_data_structures::memmap::Mmap; use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_serialize::Encoder; @@ -54,14 +55,15 @@ pub fn read_file( report_incremental_info: bool, path: &Path, nightly_build: bool, -) -> io::Result<Option<(Vec<u8>, usize)>> { - let data = match fs::read(path) { - Ok(data) => data, +) -> io::Result<Option<(Mmap, usize)>> { + let file = match fs::File::open(path) { + Ok(file) => file, Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(None), Err(err) => return Err(err), }; + let mmap = unsafe { Mmap::map(file) }?; - let mut file = io::Cursor::new(data); + let mut file = io::Cursor::new(&*mmap); // Check FILE_MAGIC { @@ -103,7 +105,7 @@ pub fn read_file( } let post_header_start_pos = file.position() as usize; - Ok(Some((file.into_inner(), post_header_start_pos))) + Ok(Some((mmap, post_header_start_pos))) } fn report_format_mismatch(report_incremental_info: bool, file: &Path, message: &str) { diff --git a/compiler/rustc_incremental/src/persist/load.rs b/compiler/rustc_incremental/src/persist/load.rs index 437d5596447..4d38556e5d2 100644 --- a/compiler/rustc_incremental/src/persist/load.rs +++ b/compiler/rustc_incremental/src/persist/load.rs @@ -1,6 +1,7 @@ //! Code to save/load the dep-graph from files. use rustc_data_structures::fx::FxHashMap; +use rustc_data_structures::memmap::Mmap; use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId}; use rustc_middle::ty::OnDiskCache; use rustc_serialize::opaque::Decoder; @@ -48,7 +49,7 @@ fn load_data( report_incremental_info: bool, path: &Path, nightly_build: bool, -) -> LoadResult<(Vec<u8>, usize)> { +) -> LoadResult<(Mmap, usize)> { match file_format::read_file(report_incremental_info, path, nightly_build) { Ok(Some(data_and_pos)) => LoadResult::Ok { data: data_and_pos }, Ok(None) => { |
