Skip to content

Commit a206121

Browse files
committed
seek instead of opening a new file handle
1 parent ea0e0f4 commit a206121

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2254,10 +2254,10 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
22542254
let root = ecx.encode_crate_root();
22552255

22562256
ecx.opaque.flush();
2257-
let mut file = std::fs::OpenOptions::new()
2258-
.write(true)
2259-
.open(path)
2260-
.unwrap_or_else(|err| tcx.sess.fatal(&format!("failed to open the file: {}", err)));
2257+
2258+
let mut file = ecx.opaque.file();
2259+
// We will return to this position after writing the root position.
2260+
let pos_before_seek = file.stream_position().unwrap();
22612261

22622262
// Encode the root position.
22632263
let header = METADATA_HEADER.len();
@@ -2267,6 +2267,9 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
22672267
file.write_all(&[(pos >> 24) as u8, (pos >> 16) as u8, (pos >> 8) as u8, (pos >> 0) as u8])
22682268
.unwrap_or_else(|err| tcx.sess.fatal(&format!("failed to write to the file: {}", err)));
22692269

2270+
// Return to the position where we are before writing the root position.
2271+
file.seek(std::io::SeekFrom::Start(pos_before_seek)).unwrap();
2272+
22702273
// Record metadata size for self-profiling
22712274
tcx.prof.artifact_size(
22722275
"crate_metadata",

0 commit comments

Comments
 (0)