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(|skull_owner| skull_owner.compound("Properties"))
.and_then(|properties| properties.list("textures")) .and_then(|properties| properties.list("textures"))
.and_then(|textures| textures.compounds()) .and_then(|textures| textures.compounds())
.and_then(|textures| textures.get(0)) .and_then(|textures| textures.first())
.and_then(|texture| texture.string("Value")) .and_then(|texture| texture.string("Value"))
// the real program does some base64+json decoding here but that's unnecessary for the benchmark // the real program does some base64+json decoding here but that's unnecessary for the benchmark
.map(|value| value.to_string()), .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| { .and_then(|textures| {
if let azalea_nbt::NbtList::Compound(textures) = textures { if let azalea_nbt::NbtList::Compound(textures) = textures {
textures textures
.get(0) .first()
.and_then(|texture| texture.get("Value")) .and_then(|texture| texture.get("Value"))
.and_then(|value| value.as_string().cloned()) .and_then(|value| value.as_string().cloned())
.map(|string| string.to_string()) .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(|skull_owner| skull_owner.compound("Properties"))
.and_then(|properties| properties.list("textures")) .and_then(|properties| properties.list("textures"))
.and_then(|textures| textures.compounds()) .and_then(|textures| textures.compounds())
.and_then(|textures| textures.get(0)) .and_then(|textures| textures.first())
.and_then(|texture| texture.string("Value")) .and_then(|texture| texture.string("Value"))
// the real program does some base64+json decoding here but that's unnecessary for the benchmark // the real program does some base64+json decoding here but that's unnecessary for the benchmark
.map(|value| value.to_string()), .map(|value| value.to_string()),

View file

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

View file

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