Skip to content

Commit

Permalink
perf: reduce to_vec default buffer capacities
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Gray <hoxxep@gmail.com>
  • Loading branch information
hoxxep committed Dec 5, 2024
1 parent 6bbfdea commit 4e8abec
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ciborium/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ where
fn to_vec_small<T: ?Sized + ser::Serialize, C: Canonicalization>(
value: &T,
) -> Result<Vec<u8>, Error<std::io::Error>> {
let mut buffer = Vec::with_capacity(256);
let mut buffer = Vec::with_capacity(32);
let mut serializer: Serializer<_, C> = Serializer::new(&mut buffer);
value.serialize(&mut serializer)?;
Ok(buffer)
Expand All @@ -765,7 +765,7 @@ fn to_vec_small<T: ?Sized + ser::Serialize, C: Canonicalization>(
#[cfg(feature = "std")]
#[inline]
pub fn to_vec<T: ?Sized + ser::Serialize>(value: &T) -> Result<Vec<u8>, Error<std::io::Error>> {
let mut buffer = Vec::with_capacity(1024);
let mut buffer = Vec::with_capacity(128);
let mut serializer: Serializer<_, NoCanonicalization> = Serializer::new(&mut buffer);
value.serialize(&mut serializer)?;
Ok(buffer)
Expand Down Expand Up @@ -795,7 +795,7 @@ pub fn to_vec<T: ?Sized + ser::Serialize>(value: &T) -> Result<Vec<u8>, Error<st
pub fn to_vec_canonical<T: ?Sized + ser::Serialize, C: Canonicalization>(
value: &T,
) -> Result<Vec<u8>, Error<std::io::Error>> {
let mut buffer = Vec::with_capacity(1024);
let mut buffer = Vec::with_capacity(128);
let mut serializer: Serializer<_, C> = Serializer::new(&mut buffer);
value.serialize(&mut serializer)?;
Ok(buffer)
Expand Down

0 comments on commit 4e8abec

Please sign in to comment.