use take() for extra fast processing of binary files

Suggested by @notoria in #589. Many thanks!
This commit is contained in:
Markus Triska
2020-06-12 21:07:18 +02:00
parent 5f1b03261c
commit f910e013a6

View File

@@ -2277,18 +2277,11 @@ impl MachineState {
let mut string = String::new(); let mut string = String::new();
if stream.options.stream_type == StreamType::Binary { if stream.options.stream_type == StreamType::Binary {
let mut mstream = stream.clone(); let mut buf = vec![];
for _ in 0..num { let mut chunk = stream.take(num as u64);
let mut b = [0u8; 1]; chunk.read_to_end(&mut buf).ok();
for c in buf {
match mstream.read(&mut b) { string.push(c as char);
Ok(1) => {
string.push(b[0] as char);
}
_ => {
break;
}
}
} }
} else { } else {
let mut iter = self.open_parsing_stream(stream.clone(), let mut iter = self.open_parsing_stream(stream.clone(),