Skip to content

Commit

Permalink
Use serde_json::to_writer for JsonEmitter::emit
Browse files Browse the repository at this point in the history
Avoids an unnecessary intermediate string.
  • Loading branch information
jsgf committed Sep 9, 2023
1 parent c070a83 commit 4854e19
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ 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.flush()
}
}

Expand Down

0 comments on commit 4854e19

Please sign in to comment.