Skip to content

Commit f081b88

Browse files
committed
minor performance improvements
1 parent ad9409a commit f081b88

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/playback.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rodio::{Decoder, OutputStream, PlayError, Sink, Source};
77
use std::collections::VecDeque;
88
use std::fs::File;
99
use std::io::BufReader;
10+
use std::io::Write;
1011
use std::path::PathBuf;
1112
use std::sync::{
1213
Arc,
@@ -31,16 +32,26 @@ fn reconstruct_frame_string(frame: &RleFrame) -> String {
3132
if current_color.is_some() {
3233
buffer.push_str("\x1b[0m");
3334
}
34-
buffer.push_str(&format!(
35+
36+
let mut w = Vec::with_capacity(20);
37+
38+
write!(
39+
w,
3540
"\x1b[38;2;{};{};{}m",
3641
run.color[0], run.color[1], run.color[2]
37-
));
42+
)
43+
.unwrap();
44+
45+
// I hope this is faster
46+
buffer.push_str(unsafe { std::str::from_utf8_unchecked(&w) });
3847
current_color = Some(run.color);
3948
}
49+
4050
let ch = ASCII_CHARS
4151
.get(run.ascii_idx as usize)
4252
.copied()
4353
.unwrap_or(' ');
54+
4455
for _ in 0..run.count {
4556
buffer.push(ch);
4657
current_col += 1;

0 commit comments

Comments
 (0)