From 9e57447ab2956532b4f635a6932ba43ef4a43c7e Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Wed, 6 Mar 2024 23:33:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96NbtReader=E7=9A=84read=5Fint?= =?UTF-8?q?=5Farray=E5=92=8Cread=5Flong=5Farray=E6=96=B9=E6=B3=95=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shen-nbt5/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shen-nbt5/src/lib.rs b/shen-nbt5/src/lib.rs index 60332a5..fedf84b 100644 --- a/shen-nbt5/src/lib.rs +++ b/shen-nbt5/src/lib.rs @@ -80,16 +80,16 @@ impl NbtReader<'_> { value.into_owned() } pub fn read_int_array(&mut self, len: usize) -> &[i32] { - let datas = self.read_u8_array(len * 4); - let value = unsafe { - std::slice::from_raw_parts(datas.as_ptr() as *const i32, len) - }; + unsafe { + self.cursor += len * 4; + std::slice::from_raw_parts(self.data[self.cursor..].as_ptr() as *const i32, len) + } } pub fn read_long_array(&mut self, len: usize) -> &[i64] { - let datas = self.read_u8_array(len * 8); - let value = unsafe { - std::slice::from_raw_parts(datas.as_ptr() as *const i64, len) - }; + unsafe { + self.cursor += len * 8; + std::slice::from_raw_parts(self.data[self.cursor..].as_ptr() as *const i64, len) + } } }