aboutsummaryrefslogtreecommitdiffstats
path: root/examples/process_diff.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-13 07:20:33 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-13 07:20:33 -0500
commit6c439e27c47d0e2d4da9c2d253a57156bf32e5d8 (patch)
tree4c4f137ae707146fa8e4de93b8ca811162b4ba5d /examples/process_diff.rs
parente85e57949df612e22463c06fc31fb0b7957ea3c7 (diff)
downloadvt100-rust-direct-write.tar.gz
vt100-rust-direct-write.zip
attempt to avoid copies by writing directly to a std::io::Writedirect-write
this turns out to be slower, i think because it ends up doing a much larger number of small writes, and the copying overhead isn't as high as going through all of the machinery involved in stdout locking/buffering/syscalls/etc.
Diffstat (limited to 'examples/process_diff.rs')
-rw-r--r--examples/process_diff.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/examples/process_diff.rs b/examples/process_diff.rs
index c141269..55ebbf2 100644
--- a/examples/process_diff.rs
+++ b/examples/process_diff.rs
@@ -1,4 +1,4 @@
-use std::io::{Read as _, Write as _};
+use std::io::Read as _;
fn read_frames() -> impl Iterator<Item = Vec<u8>> {
(1..=7625).map(|i| {
@@ -14,13 +14,13 @@ fn read_frames() -> impl Iterator<Item = Vec<u8>> {
fn draw_frames(frames: &[Vec<u8>]) {
let mut stdout = std::io::stdout();
let mut parser = vt100::Parser::default();
- let mut screen = parser.screen().clone();
for frame in frames {
+ let screen = parser.screen().clone();
parser.process(&frame);
- let new_screen = parser.screen().clone();
- let diff = new_screen.contents_diff(&screen);
- stdout.write_all(&diff).unwrap();
- screen = new_screen;
+ parser
+ .screen()
+ .write_contents_diff(&mut stdout, &screen)
+ .unwrap();
}
}