Skip to content

Commit 537b5b3

Browse files
committed
Use serde_json::to_writer for JsonEmitter::emit
Avoids an unnecessary intermediate string.
1 parent c070a83 commit 537b5b3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

compiler/rustc_errors/src/json.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,12 @@ impl JsonEmitter {
141141

142142
fn emit(&mut self, val: EmitTyped<'_>) -> io::Result<()> {
143143
if self.pretty {
144-
writeln!(self.dst, "{}", serde_json::to_string_pretty(&val).unwrap())
144+
serde_json::to_writer_pretty(&mut *self.dst, &val)?
145145
} else {
146-
writeln!(self.dst, "{}", serde_json::to_string(&val).unwrap())
147-
}
148-
.and_then(|_| self.dst.flush())
146+
serde_json::to_writer(&mut *self.dst, &val)?
147+
};
148+
self.dst.write_all(b"\n")?;
149+
self.dst.flush()
149150
}
150151
}
151152

0 commit comments

Comments
 (0)