优化NbtReader的read_int_array和read_long_array方法实现
This commit is contained in:
parent
1dee92147d
commit
9e57447ab2
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user