mirror of
https://github.com/azalea-rs/simdnbt.git
synced 2025-08-02 23:44:40 +00:00
slightly optimize lists of non-recursing non-primitives
This commit is contained in:
parent
f47749f7a8
commit
ac66cd4031
2 changed files with 18 additions and 12 deletions
|
@ -58,33 +58,33 @@ impl<'a> NbtList<'a> {
|
||||||
DOUBLE_ID => NbtList::Double(RawList::new(read_with_u32_length(data, 8)?)),
|
DOUBLE_ID => NbtList::Double(RawList::new(read_with_u32_length(data, 8)?)),
|
||||||
BYTE_ARRAY_ID => NbtList::ByteArray({
|
BYTE_ARRAY_ID => NbtList::ByteArray({
|
||||||
let length = read_u32(data)?;
|
let length = read_u32(data)?;
|
||||||
let mut tags = alloc.get().unnamed_bytearray.start(list_depth);
|
let mut tags = alloc.get().unnamed_bytearray.start(0);
|
||||||
for _ in 0..length {
|
for _ in 0..length {
|
||||||
let tag = match read_u8_array(data) {
|
let tag = match read_u8_array(data) {
|
||||||
Ok(tag) => tag,
|
Ok(tag) => tag,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
alloc.get().unnamed_bytearray.finish(tags, list_depth);
|
alloc.get().unnamed_bytearray.finish(tags, 0);
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
tags.push(tag);
|
tags.push(tag);
|
||||||
}
|
}
|
||||||
alloc.get().unnamed_bytearray.finish(tags, list_depth)
|
alloc.get().unnamed_bytearray.finish(tags, 0)
|
||||||
}),
|
}),
|
||||||
STRING_ID => NbtList::String({
|
STRING_ID => NbtList::String({
|
||||||
let length = read_u32(data)?;
|
let length = read_u32(data)?;
|
||||||
let mut tags = alloc.get().unnamed_string.start(list_depth);
|
let mut tags = alloc.get().unnamed_string.start(0);
|
||||||
for _ in 0..length {
|
for _ in 0..length {
|
||||||
let tag = match read_string(data) {
|
let tag = match read_string(data) {
|
||||||
Ok(tag) => tag,
|
Ok(tag) => tag,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
alloc.get().unnamed_string.finish(tags, list_depth);
|
alloc.get().unnamed_string.finish(tags, 0);
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
tags.push(tag);
|
tags.push(tag);
|
||||||
}
|
}
|
||||||
alloc.get().unnamed_string.finish(tags, list_depth)
|
alloc.get().unnamed_string.finish(tags, 0)
|
||||||
}),
|
}),
|
||||||
LIST_ID => NbtList::List({
|
LIST_ID => NbtList::List({
|
||||||
let length = read_u32(data)?;
|
let length = read_u32(data)?;
|
||||||
|
@ -123,33 +123,33 @@ impl<'a> NbtList<'a> {
|
||||||
}),
|
}),
|
||||||
INT_ARRAY_ID => NbtList::IntArray({
|
INT_ARRAY_ID => NbtList::IntArray({
|
||||||
let length = read_u32(data)?;
|
let length = read_u32(data)?;
|
||||||
let mut tags = alloc.get().unnamed_intarray.start(list_depth);
|
let mut tags = alloc.get().unnamed_intarray.start(0);
|
||||||
for _ in 0..length {
|
for _ in 0..length {
|
||||||
let tag = match read_int_array(data) {
|
let tag = match read_int_array(data) {
|
||||||
Ok(tag) => tag,
|
Ok(tag) => tag,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
alloc.get().unnamed_intarray.finish(tags, list_depth);
|
alloc.get().unnamed_intarray.finish(tags, 0);
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
tags.push(tag);
|
tags.push(tag);
|
||||||
}
|
}
|
||||||
alloc.get().unnamed_intarray.finish(tags, list_depth)
|
alloc.get().unnamed_intarray.finish(tags, 0)
|
||||||
}),
|
}),
|
||||||
LONG_ARRAY_ID => NbtList::LongArray({
|
LONG_ARRAY_ID => NbtList::LongArray({
|
||||||
let length = read_u32(data)?;
|
let length = read_u32(data)?;
|
||||||
let mut tags = alloc.get().unnamed_longarray.start(list_depth);
|
let mut tags = alloc.get().unnamed_longarray.start(0);
|
||||||
for _ in 0..length {
|
for _ in 0..length {
|
||||||
let tag = match read_long_array(data) {
|
let tag = match read_long_array(data) {
|
||||||
Ok(tag) => tag,
|
Ok(tag) => tag,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
alloc.get().unnamed_longarray.finish(tags, list_depth);
|
alloc.get().unnamed_longarray.finish(tags, 0);
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
tags.push(tag);
|
tags.push(tag);
|
||||||
}
|
}
|
||||||
alloc.get().unnamed_longarray.finish(tags, list_depth)
|
alloc.get().unnamed_longarray.finish(tags, 0)
|
||||||
}),
|
}),
|
||||||
_ => return Err(Error::UnknownTagId(tag_type)),
|
_ => return Err(Error::UnknownTagId(tag_type)),
|
||||||
})
|
})
|
||||||
|
|
|
@ -359,6 +359,12 @@ mod tests {
|
||||||
assert_eq!(nbt.list("Rotation").unwrap().floats().unwrap().len(), 2);
|
assert_eq!(nbt.list("Rotation").unwrap().floats().unwrap().len(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_realworld() {
|
||||||
|
let src = include_bytes!("../../tests/realworld.nbt").to_vec();
|
||||||
|
let _nbt = Nbt::read(&mut Cursor::new(&src[..])).unwrap().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn read_write_complex_player() {
|
fn read_write_complex_player() {
|
||||||
let src = include_bytes!("../../tests/complex_player.dat").to_vec();
|
let src = include_bytes!("../../tests/complex_player.dat").to_vec();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue