From 6af2c284c976b10c5d2e105af7fe961e2a3b5c54 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sat, 13 Jan 2024 01:49:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E5=8A=A0=E7=82=B9=20inline(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- v2/src/data_struct.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/v2/src/data_struct.rs b/v2/src/data_struct.rs index 1f6b22b..9ef2b27 100644 --- a/v2/src/data_struct.rs +++ b/v2/src/data_struct.rs @@ -83,10 +83,12 @@ impl NbtData { pub mod raw_reading { /// 多少有点脱裤子放屁 + #[inline(always)] pub fn slice_as_byte_array(slice: &[u8]) -> Vec { slice.iter().map(|&x| x as i8).collect::>() } /// unsafe 从这里开始 + #[inline(always)] pub fn slice_as_short_array(slice: &[u8]) -> Option> { let length = if slice.len() % 2 != 0 { return None; @@ -97,6 +99,7 @@ pub mod raw_reading { } /// 开始 unsafe 了 /// unsafe rust, 小子! + #[inline(always)] pub fn slice_as_int_array(slice: &[u8]) -> Option> { let length = if slice.len() % 4 != 0 { return None; @@ -106,6 +109,7 @@ pub mod raw_reading { Some(unsafe { std::slice::from_raw_parts(slice.as_ptr() as *mut i32, length).to_vec() }) } /// 这边也是 unsafe 捏 + #[inline(always)] pub fn slice_as_long_array(slice: &[u8]) -> Option> { let length = if slice.len() % 8 != 0 { return None; @@ -115,6 +119,7 @@ pub mod raw_reading { Some(unsafe { std::slice::from_raw_parts(slice.as_ptr() as *mut i64, length).to_vec() }) } /// 这边也是 unsafe 捏 + #[inline(always)] pub fn slice_as_float_array(slice: &[u8]) -> Option> { let length = if slice.len() % 4 != 0 { return None; @@ -124,6 +129,7 @@ pub mod raw_reading { Some(unsafe { std::slice::from_raw_parts(slice.as_ptr() as *mut f32, length).to_vec() }) } /// 这边也是 unsafe 捏 + #[inline(always)] pub fn slice_as_double_array(slice: &[u8]) -> Option> { let length = if slice.len() % 8 != 0 { return None; @@ -418,12 +424,14 @@ impl<'value> Value<'value> { _ => None, } } + #[inline(always)] pub fn into_list(self) -> Option> { match self { Self::List(value) => Some(value), _ => None, } } + #[inline(always)] pub fn into_compound(self) -> Option)>> { match self { Self::Compound(value) => Some(value),