@@ -4,7 +4,7 @@ use crate::rmeta::*;
44
55use rustc_data_structures:: fingerprint:: Fingerprint ;
66use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
7- use rustc_data_structures:: memmap:: Mmap ;
7+ use rustc_data_structures:: memmap:: { Mmap , MmapMut } ;
88use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
99use rustc_data_structures:: sync:: { join, par_iter, Lrc , ParallelIterator } ;
1010use rustc_data_structures:: temp_dir:: MaybeTempDir ;
@@ -44,7 +44,6 @@ use std::io::{Read, Seek, Write};
4444use std:: iter;
4545use std:: num:: NonZeroUsize ;
4646use std:: path:: { Path , PathBuf } ;
47- use tempfile:: Builder as TempFileBuilder ;
4847use tracing:: { debug, trace} ;
4948
5049pub ( super ) struct EncodeContext < ' a , ' tcx > {
@@ -2179,19 +2178,19 @@ impl<S: Encoder> Encodable<S> for EncodedMetadata {
21792178
21802179impl < D : Decoder > Decodable < D > for EncodedMetadata {
21812180 fn decode ( d : & mut D ) -> Self {
2182- let temp_dir = TempFileBuilder :: new ( ) . prefix ( "decoded" ) . tempdir ( ) . unwrap ( ) ;
2183- let temp_dir = MaybeTempDir :: new ( temp_dir, false ) ;
2184- let filename = temp_dir. as_ref ( ) . join ( "decoded" ) ;
2185- let file = std:: fs:: File :: create ( & filename) . unwrap ( ) ;
2186- let mut file = std:: io:: BufWriter :: new ( file) ;
2187-
21882181 let len = d. read_usize ( ) ;
2189- for _ in 0 ..len {
2190- file. write ( & [ d. read_u8 ( ) ] ) . unwrap ( ) ;
2191- }
2192- file. flush ( ) . unwrap ( ) ;
2182+ let mmap = if len > 0 {
2183+ let mut mmap = MmapMut :: map_anon ( len) . unwrap ( ) ;
2184+ for _ in 0 ..len {
2185+ ( & mut mmap[ ..] ) . write ( & [ d. read_u8 ( ) ] ) . unwrap ( ) ;
2186+ }
2187+ mmap. flush ( ) . unwrap ( ) ;
2188+ Some ( mmap. make_read_only ( ) . unwrap ( ) )
2189+ } else {
2190+ None
2191+ } ;
21932192
2194- Self :: from_path ( filename , Some ( temp_dir ) ) . unwrap ( )
2193+ Self { mmap , _temp_dir : None }
21952194 }
21962195}
21972196
0 commit comments