From 5bc3363dd7838fd94c99c5179a56869ced5b5bad Mon Sep 17 00:00:00 2001 From: SzczurekYT Date: Mon, 25 Mar 2024 22:08:45 +0100 Subject: [PATCH] perf: Avoid copying bytes when deserializing strings --- src/nbt/utils.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/nbt/utils.rs b/src/nbt/utils.rs index 4c7490d..e670783 100644 --- a/src/nbt/utils.rs +++ b/src/nbt/utils.rs @@ -18,8 +18,7 @@ pub const LONG_ARRAY_ID: u8 = 12; pub fn get_nbt_string(bytes: &mut Bytes) -> Result { 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()) }