Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary allocation/copy from the string serialization implementation #566

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading