about summary refs log tree commit diff
path: root/compiler/rustc_incremental/src/persist/file_format.rs
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2021-03-16 21:39:03 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2021-08-28 21:45:02 +0200
commit4afdeaaabd021bf5ac03d74c7577747ccbb926d0 (patch)
treec8c992d102a9c9691b6d09a5e819f200c0d987af /compiler/rustc_incremental/src/persist/file_format.rs
parent05cccdc9b321e6565b3e62e8b52aec53d106ef2f (diff)
downloadrust-4afdeaaabd021bf5ac03d74c7577747ccbb926d0.tar.gz
rust-4afdeaaabd021bf5ac03d74c7577747ccbb926d0.zip
Mmap the incremental data instead of reading it.
Diffstat (limited to 'compiler/rustc_incremental/src/persist/file_format.rs')
-rw-r--r--compiler/rustc_incremental/src/persist/file_format.rs12
1 files changed, 7 insertions, 5 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) {