Skip to content

Commit 1be5805

Browse files
committed
use BufReader for counting zero bytes
1 parent 34f8889 commit 1be5805

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_span::{
4040
use rustc_target::abi::VariantIdx;
4141
use std::borrow::Borrow;
4242
use std::hash::Hash;
43-
use std::io::{Seek, Write};
43+
use std::io::{Read, Seek, Write};
4444
use std::iter;
4545
use std::num::NonZeroUsize;
4646
use std::path::{Path, PathBuf};
@@ -734,26 +734,26 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
734734
assert_eq!(total_bytes, computed_total_bytes);
735735

736736
if tcx.sess.meta_stats() {
737-
// let mut zero_bytes = 0;
738-
// for e in self.opaque.data.iter() {
739-
// if *e == 0 {
740-
// zero_bytes += 1;
741-
// }
742-
// }
737+
let mut zero_bytes = 0;
738+
let file = std::io::BufReader::new(self.opaque.file());
739+
for e in file.bytes() {
740+
if e.unwrap() == 0 {
741+
zero_bytes += 1;
742+
}
743+
}
743744

744745
let perc = |bytes| (bytes * 100) as f64 / total_bytes as f64;
745746
let p = |label, bytes| {
746747
eprintln!("{:>21}: {:>8} bytes ({:4.1}%)", label, bytes, perc(bytes));
747748
};
748749

749750
eprintln!("");
750-
// FIXME print zero bytes
751-
//eprintln!(
752-
// "{} metadata bytes, of which {} bytes ({:.1}%) are zero",
753-
// total_bytes,
754-
// zero_bytes,
755-
// perc(zero_bytes)
756-
//);
751+
eprintln!(
752+
"{} metadata bytes, of which {} bytes ({:.1}%) are zero",
753+
total_bytes,
754+
zero_bytes,
755+
perc(zero_bytes)
756+
);
757757
p("preamble", preamble_bytes);
758758
p("dep", dep_bytes);
759759
p("lib feature", lib_feature_bytes);

compiler/rustc_serialize/src/opaque.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ impl FileEncoder {
297297
}
298298
}
299299

300+
pub fn file(&self) -> &File {
301+
&self.file
302+
}
303+
300304
#[inline]
301305
fn capacity(&self) -> usize {
302306
self.buf.len()

0 commit comments

Comments
 (0)