mirror of
https://github.com/azalea-rs/simdnbt.git
synced 2025-08-02 07:26:04 +00:00
cleanup and minor optimization by updating TapeTagKind
This commit is contained in:
parent
16e90028be
commit
886ef3d164
5 changed files with 13 additions and 13 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -5,8 +5,8 @@
|
|||
flamegraph.svg
|
||||
perf.data
|
||||
perf.data.old
|
||||
callgrind.out.*
|
||||
cachegrind.out.*
|
||||
callgrind.out*
|
||||
cachegrind.out*
|
||||
|
||||
# sometimes i make these files when benchmarking, don't want to accidentally commit them
|
||||
benchmark_result.txt
|
||||
|
|
|
@ -328,12 +328,6 @@ pub(crate) fn read_tag<'a>(
|
|||
stack: &mut ParsingStack,
|
||||
tag_type: u8,
|
||||
) -> Result<(), NonRootError> {
|
||||
match tag_type {
|
||||
COMPOUND_ID => return NbtCompound::read(data, tapes, stack),
|
||||
LIST_ID => return NbtList::read(data, tapes, stack),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let pushing_element = match tag_type {
|
||||
BYTE_ID => {
|
||||
let byte = data.read_i8()?;
|
||||
|
@ -376,6 +370,8 @@ pub(crate) fn read_tag<'a>(
|
|||
|
||||
TapeElement::new_with_ptr(TapeTagKind::String, string_ptr)
|
||||
}
|
||||
COMPOUND_ID => return NbtCompound::read(data, tapes, stack),
|
||||
LIST_ID => return NbtList::read(data, tapes, stack),
|
||||
INT_ARRAY_ID => {
|
||||
let int_array_ptr = data.cur;
|
||||
read_int_array(data)?;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{hint::unreachable_unchecked, marker::PhantomData};
|
||||
use std::{hint::unreachable_unchecked, marker::PhantomData, mem};
|
||||
|
||||
use crate::{
|
||||
common::{
|
||||
|
@ -810,7 +810,7 @@ where
|
|||
let length = unsafe { u32::from(*ptr) };
|
||||
#[cfg(target_endian = "little")]
|
||||
let length = length.swap_bytes();
|
||||
let length_in_bytes = length as usize * std::mem::size_of::<T>();
|
||||
let length_in_bytes = length as usize * mem::size_of::<T>();
|
||||
let array_be = unsafe { std::slice::from_raw_parts(ptr.add(1) as *const u8, length_in_bytes) };
|
||||
Some(RawList::new(array_be))
|
||||
}
|
||||
|
|
|
@ -226,6 +226,9 @@ impl From<UnalignedU16> for u16 {
|
|||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum TapeTagKind {
|
||||
// putting this at the start makes it slightly faster
|
||||
EmptyList = 0,
|
||||
|
||||
Byte = BYTE_ID,
|
||||
Short = SHORT_ID,
|
||||
Int = INT_ID,
|
||||
|
@ -238,7 +241,6 @@ pub enum TapeTagKind {
|
|||
IntArray = INT_ARRAY_ID,
|
||||
LongArray = LONG_ARRAY_ID,
|
||||
|
||||
EmptyList,
|
||||
ByteList,
|
||||
ShortList,
|
||||
IntList,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::{
|
||||
io::Cursor,
|
||||
marker::PhantomData,
|
||||
mem,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
|
@ -33,14 +34,15 @@ impl<'a> Reader<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn unchecked_read_type<T>(&mut self) -> T {
|
||||
let value = unsafe { self.cur.cast::<T>().read_unaligned() };
|
||||
self.cur = unsafe { self.cur.add(std::mem::size_of::<T>()) };
|
||||
self.cur = unsafe { self.cur.add(mem::size_of::<T>()) };
|
||||
value
|
||||
}
|
||||
|
||||
pub fn read_type<T: Copy>(&mut self) -> Result<T, UnexpectedEofError> {
|
||||
self.ensure_can_read(std::mem::size_of::<T>())?;
|
||||
self.ensure_can_read(mem::size_of::<T>())?;
|
||||
Ok(unsafe { self.unchecked_read_type() })
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue