mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 00:51:11 -05:00
perf(report): Reduce grabbing of locks
This commit is contained in:
parent
3d1fb3b1ae
commit
a082207283
1 changed files with 22 additions and 8 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize)]
|
#[derive(Copy, Clone, Debug, Serialize)]
|
||||||
pub struct Message<'m> {
|
pub struct Message<'m> {
|
||||||
pub path: &'m std::path::Path,
|
pub path: &'m std::path::Path,
|
||||||
|
@ -33,21 +35,33 @@ pub fn print_long(msg: Message) {
|
||||||
let hl_indent: String = itertools::repeat_n(" ", msg.col_num).collect();
|
let hl_indent: String = itertools::repeat_n(" ", msg.col_num).collect();
|
||||||
let hl: String = itertools::repeat_n("^", msg.word.len()).collect();
|
let hl: String = itertools::repeat_n("^", msg.word.len()).collect();
|
||||||
|
|
||||||
println!("error: `{}` should be `{}`", msg.word, msg.correction);
|
let stdout = io::stdout();
|
||||||
println!(
|
let mut handle = stdout.lock();
|
||||||
|
|
||||||
|
writeln!(
|
||||||
|
handle,
|
||||||
|
"error: `{}` should be `{}`",
|
||||||
|
msg.word, msg.correction
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
writeln!(
|
||||||
|
handle,
|
||||||
" --> {}:{}:{}",
|
" --> {}:{}:{}",
|
||||||
msg.path.display(),
|
msg.path.display(),
|
||||||
msg.line_num,
|
msg.line_num,
|
||||||
msg.col_num
|
msg.col_num
|
||||||
);
|
)
|
||||||
println!("{} |", line_indent);
|
.unwrap();
|
||||||
println!(
|
writeln!(handle, "{} |", line_indent).unwrap();
|
||||||
|
writeln!(
|
||||||
|
handle,
|
||||||
"{} | {}",
|
"{} | {}",
|
||||||
msg.line_num,
|
msg.line_num,
|
||||||
String::from_utf8_lossy(msg.line).trim_end()
|
String::from_utf8_lossy(msg.line).trim_end()
|
||||||
);
|
)
|
||||||
println!("{} | {}{}", line_indent, hl_indent, hl);
|
.unwrap();
|
||||||
println!("{} |", line_indent);
|
writeln!(handle, "{} | {}{}", line_indent, hl_indent, hl).unwrap();
|
||||||
|
writeln!(handle, "{} |", line_indent).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_json(msg: Message) {
|
pub fn print_json(msg: Message) {
|
||||||
|
|
Loading…
Reference in a new issue