From ff8bf0ce7a2af47d40a969a0b386745e3d99b6e8 Mon Sep 17 00:00:00 2001 From: David Frank Date: Fri, 9 Aug 2024 12:39:21 +0000 Subject: [PATCH] Remove unnecessary allocation/copy from the string serialization implementation --- rust/candid/src/ser.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/candid/src/ser.rs b/rust/candid/src/ser.rs index 15750555..79064070 100644 --- a/rust/candid/src/ser.rs +++ b/rust/candid/src/ser.rs @@ -147,9 +147,9 @@ impl<'a> types::Serializer for &'a mut ValueSerializer { serialize_num!(float64, f64, write_f64::); fn serialize_text(self, v: &str) -> Result<()> { - let mut buf = Vec::from(v.as_bytes()); + let buf = v.as_bytes(); self.write_leb128(buf.len() as u64)?; - self.value.append(&mut buf); + self.value.extend_from_slice(buf); Ok(()) } fn serialize_null(self, _v: ()) -> Result<()> { @@ -316,9 +316,9 @@ impl TypeSerialize { sleb128_encode(&mut buf, Opcode::Service as i64)?; leb128_encode(&mut buf, ms.len() as u64)?; for (id, ty) in ms { - let mut name = Vec::from(id.as_bytes()); + let name = id.as_bytes(); leb128_encode(&mut buf, name.len() as u64)?; - buf.append(&mut name); + buf.extend_from_slice(name); self.encode(&mut buf, ty)?; } }