Skip to content

Commit

Permalink
Remove unnecessary allocation/copy from the string serialization impl…
Browse files Browse the repository at this point in the history
…ementation (#566)
  • Loading branch information
frankdavid authored Aug 9, 2024
1 parent 34b4eb0 commit bba0b53
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions rust/candid/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ impl<'a> types::Serializer for &'a mut ValueSerializer {
serialize_num!(float64, f64, write_f64::<LittleEndian>);

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<()> {
Expand Down Expand Up @@ -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)?;
}
}
Expand Down

0 comments on commit bba0b53

Please sign in to comment.