1
0
Fork 0
mirror of https://github.com/azalea-rs/simdnbt.git synced 2025-08-02 07:26:04 +00:00
This commit is contained in:
mat 2024-03-09 18:14:34 -06:00
parent 73ab006f7c
commit 041deb5db6
4 changed files with 27 additions and 54 deletions

View file

@ -125,7 +125,7 @@ fn simdnbt_items_from_nbt(nbt: simdnbt::borrow::BaseNbt) -> Option<Vec<Option<It
.and_then(|skull_owner| skull_owner.compound("Properties"))
.and_then(|properties| properties.list("textures"))
.and_then(|textures| textures.compounds())
.and_then(|textures| textures.get(0))
.and_then(|textures| textures.first())
.and_then(|texture| texture.string("Value"))
// the real program does some base64+json decoding here but that's unnecessary for the benchmark
.map(|value| value.to_string()),
@ -215,7 +215,7 @@ fn azalea_items_from_nbt(nbt: azalea_nbt::Nbt) -> Option<Vec<Option<Item>>> {
.and_then(|textures| {
if let azalea_nbt::NbtList::Compound(textures) = textures {
textures
.get(0)
.first()
.and_then(|texture| texture.get("Value"))
.and_then(|value| value.as_string().cloned())
.map(|string| string.to_string())

View file

@ -57,7 +57,7 @@ fn items_from_nbt(nbt: BaseNbt) -> Option<Vec<Option<Item>>> {
.and_then(|skull_owner| skull_owner.compound("Properties"))
.and_then(|properties| properties.list("textures"))
.and_then(|textures| textures.compounds())
.and_then(|textures| textures.get(0))
.and_then(|textures| textures.first())
.and_then(|texture| texture.string("Value"))
// the real program does some base64+json decoding here but that's unnecessary for the benchmark
.map(|value| value.to_string()),

View file

@ -315,27 +315,23 @@ impl<'a> NbtList<'a> {
NbtList::Short(shorts) => shorts
.to_vec()
.into_iter()
.map(|short| super::NbtTag::Short(short))
.collect(),
NbtList::Int(ints) => ints
.to_vec()
.into_iter()
.map(|int| super::NbtTag::Int(int))
.map(super::NbtTag::Short)
.collect(),
NbtList::Int(ints) => ints.to_vec().into_iter().map(super::NbtTag::Int).collect(),
NbtList::Long(longs) => longs
.to_vec()
.into_iter()
.map(|long| super::NbtTag::Long(long))
.map(super::NbtTag::Long)
.collect(),
NbtList::Float(floats) => floats
.to_vec()
.into_iter()
.map(|float| super::NbtTag::Float(float))
.map(super::NbtTag::Float)
.collect(),
NbtList::Double(doubles) => doubles
.to_vec()
.into_iter()
.map(|double| super::NbtTag::Double(double))
.map(super::NbtTag::Double)
.collect(),
NbtList::ByteArray(byte_arrays) => byte_arrays
.iter()

View file

@ -355,60 +355,37 @@ impl NbtList {
pub fn as_nbt_tags(&self) -> Vec<super::NbtTag> {
match self {
NbtList::Empty => vec![],
NbtList::Byte(bytes) => bytes
.iter()
.map(|&byte| super::NbtTag::Byte(byte))
.collect(),
NbtList::Short(shorts) => shorts
.to_vec()
.into_iter()
.map(|short| super::NbtTag::Short(short))
.collect(),
NbtList::Int(ints) => ints
.to_vec()
.into_iter()
.map(|int| super::NbtTag::Int(int))
.collect(),
NbtList::Long(longs) => longs
.to_vec()
.into_iter()
.map(|long| super::NbtTag::Long(long))
.collect(),
NbtList::Float(floats) => floats
.to_vec()
.into_iter()
.map(|float| super::NbtTag::Float(float))
.collect(),
NbtList::Double(doubles) => doubles
.to_vec()
.into_iter()
.map(|double| super::NbtTag::Double(double))
.collect(),
NbtList::Byte(bytes) => bytes.iter().copied().map(super::NbtTag::Byte).collect(),
NbtList::Short(shorts) => shorts.iter().copied().map(super::NbtTag::Short).collect(),
NbtList::Int(ints) => ints.iter().copied().map(super::NbtTag::Int).collect(),
NbtList::Long(longs) => longs.iter().copied().map(super::NbtTag::Long).collect(),
NbtList::Float(floats) => floats.iter().copied().map(super::NbtTag::Float).collect(),
NbtList::Double(doubles) => {
doubles.iter().copied().map(super::NbtTag::Double).collect()
}
NbtList::ByteArray(byte_arrays) => byte_arrays
.iter()
.cloned()
.map(|array| super::NbtTag::ByteArray(array))
.collect(),
NbtList::String(strings) => strings
.iter()
.cloned()
.map(|string| super::NbtTag::String(string))
.collect(),
NbtList::List(lists) => lists
.iter()
.map(|list| super::NbtTag::List(list.clone()))
.map(super::NbtTag::ByteArray)
.collect(),
NbtList::String(strings) => {
strings.iter().cloned().map(super::NbtTag::String).collect()
}
NbtList::List(lists) => lists.iter().cloned().map(super::NbtTag::List).collect(),
NbtList::Compound(compounds) => compounds
.iter()
.map(|compound| super::NbtTag::Compound(compound.clone()))
.cloned()
.map(super::NbtTag::Compound)
.collect(),
NbtList::IntArray(int_arrays) => int_arrays
.iter()
.map(|array| super::NbtTag::IntArray(array.clone()))
.cloned()
.map(super::NbtTag::IntArray)
.collect(),
NbtList::LongArray(long_arrays) => long_arrays
.iter()
.map(|array| super::NbtTag::LongArray(array.clone()))
.cloned()
.map(super::NbtTag::LongArray)
.collect(),
}
}