Skip to content

Commit

Permalink
perf: Avoid copying bytes when deserializing strings
Browse files Browse the repository at this point in the history
  • Loading branch information
SzczurekYT authored and Norbiros committed Mar 25, 2024
1 parent fb0d91a commit 5bc3363
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/nbt/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ pub const LONG_ARRAY_ID: u8 = 12;

pub fn get_nbt_string(bytes: &mut Bytes) -> Result<String, Error> {
let len = bytes.get_u16() as usize;
let string_bytes = bytes[..len].to_vec();
let string_bytes = bytes.copy_to_bytes(len);
let string = from_java_cesu8(&string_bytes).map_err(|_| Error::InvalidJavaString)?;
bytes.advance(len);
Ok(string.to_string())
}

0 comments on commit 5bc3363

Please sign in to comment.