Skip to content

Commit

Permalink
chore: Match capacity of serde_json::to_vec (#11565)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Sichert <mail@pablosichert.com>
  • Loading branch information
pablosichert authored Feb 25, 2022
1 parent a1b72e2 commit 801ee21
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ pub mod json {
where
T: ?Sized + Serialize,
{
let mut bytes = BytesMut::new();
// Allocate same capacity as `serde_json::to_vec`:
// https://github.com/serde-rs/json/blob/5fe9bdd3562bf29d02d1ab798bbcff069173306b/src/ser.rs#L2195.
let mut bytes = BytesMut::with_capacity(128);
serde_json::to_writer((&mut bytes).writer(), value)?;
Ok(bytes)
}
Expand Down

0 comments on commit 801ee21

Please sign in to comment.