Lock stdout once when printing diagnostics (#1901)

https://doc.rust-lang.org/stable/std/io/struct.Stdout.html

> Each handle shares a global buffer of data to be written to the standard output stream.
> Access is also synchronized via a lock and
> explicit control over locking is available via the [`lock`](https://doc.rust-lang.org/stable/std/io/struct.Stdout.html#method.lock) method.
This commit is contained in:
messense 2023-01-16 10:04:00 +08:00 committed by GitHub
parent d71a615b18
commit cb4f305ced
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -122,7 +122,7 @@ impl<'a> Printer<'a> {
}
if matches!(self.violations, Violations::Hide) {
let mut stdout = BufWriter::new(io::stdout());
let mut stdout = BufWriter::new(io::stdout().lock());
if matches!(
self.format,
SerializationFormat::Text | SerializationFormat::Grouped
@ -132,7 +132,7 @@ impl<'a> Printer<'a> {
return Ok(());
}
let mut stdout = BufWriter::new(io::stdout());
let mut stdout = BufWriter::new(io::stdout().lock());
match self.format {
SerializationFormat::Json => {
writeln!(
@ -312,7 +312,7 @@ impl<'a> Printer<'a> {
);
}
let mut stdout = BufWriter::new(io::stdout());
let mut stdout = BufWriter::new(io::stdout().lock());
if !diagnostics.messages.is_empty() {
if self.log_level >= &LogLevel::Default {
writeln!(stdout)?;