about summary refs log tree commit diff
path: root/compiler/rustc_errors/src
diff options
context:
space:
mode:
authorJeremy Fitzhardinge <jeremy@goop.org>2023-09-09 11:30:23 -0700
committerJeremy Fitzhardinge <jsgf@fb.com>2023-09-19 14:17:02 -0700
commit00adbb2d5a4e490dd7838a6f9a6839e2cf197d17 (patch)
treedea6768bd7bdf78a7ef4671442b8d15a9b8c3089 /compiler/rustc_errors/src
parent54267ddc0c582b15838bc9c7741e70a8321914bf (diff)
downloadrust-00adbb2d5a4e490dd7838a6f9a6839e2cf197d17.tar.gz
rust-00adbb2d5a4e490dd7838a6f9a6839e2cf197d17.zip
Use serde_json::to_writer for JsonEmitter::emit
Avoids an unnecessary intermediate string.
Diffstat (limited to 'compiler/rustc_errors/src')
-rw-r--r--compiler/rustc_errors/src/json.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/rustc_errors/src/json.rs b/compiler/rustc_errors/src/json.rs
index 2050600ee08..e89e443dbcb 100644
--- a/compiler/rustc_errors/src/json.rs
+++ b/compiler/rustc_errors/src/json.rs
@@ -148,11 +148,12 @@ impl JsonEmitter {
 
     fn emit(&mut self, val: EmitTyped<'_>) -> io::Result<()> {
         if self.pretty {
-            writeln!(self.dst, "{}", serde_json::to_string_pretty(&val).unwrap())
+            serde_json::to_writer_pretty(&mut *self.dst, &val)?
         } else {
-            writeln!(self.dst, "{}", serde_json::to_string(&val).unwrap())
-        }
-        .and_then(|_| self.dst.flush())
+            serde_json::to_writer(&mut *self.dst, &val)?
+        };
+        self.dst.write_all(b"\n")?;
+        self.dst.flush()
     }
 }