mirror of
https://github.com/azalea-rs/simdnbt.git
synced 2025-08-02 23:44:40 +00:00
get(0) -> first()
This commit is contained in:
parent
024e88a78e
commit
d7547067ee
4 changed files with 15 additions and 3 deletions
|
@ -26,7 +26,7 @@ fn example(item_bytes: &[u8]) {
|
|||
let skyblock_id: Cow<str> = nbt
|
||||
.list("i")
|
||||
.and_then(|i| i.compounds())
|
||||
.and_then(|i| i.get(0))
|
||||
.and_then(|i| i.first())
|
||||
.and_then(|i| i.compound("tag"))
|
||||
.and_then(|tag| tag.compound("ExtraAttributes"))
|
||||
.and_then(|ea| ea.string("id"))
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -613,6 +613,12 @@ impl<'a, 'tape> ListList<'a, 'tape> {
|
|||
pub fn get(&self, index: usize) -> Option<NbtList<'a, 'tape>> {
|
||||
self.iter.clone().nth(index)
|
||||
}
|
||||
pub fn first(&self) -> Option<NbtList<'a, 'tape>> {
|
||||
self.iter.clone().next()
|
||||
}
|
||||
pub fn last(&self) -> Option<NbtList<'a, 'tape>> {
|
||||
self.iter.clone().last()
|
||||
}
|
||||
}
|
||||
impl<'a: 'tape, 'tape> IntoIterator for ListList<'a, 'tape> {
|
||||
type Item = NbtList<'a, 'tape>;
|
||||
|
@ -715,6 +721,12 @@ impl<'a, 'tape> CompoundList<'a, 'tape> {
|
|||
pub fn get(&self, index: usize) -> Option<NbtCompound<'a, 'tape>> {
|
||||
self.iter.clone().nth(index)
|
||||
}
|
||||
pub fn first(&self) -> Option<NbtCompound<'a, 'tape>> {
|
||||
self.iter.clone().next()
|
||||
}
|
||||
pub fn last(&self) -> Option<NbtCompound<'a, 'tape>> {
|
||||
self.iter.clone().last()
|
||||
}
|
||||
}
|
||||
impl<'a: 'tape, 'tape> IntoIterator for CompoundList<'a, 'tape> {
|
||||
type Item = NbtCompound<'a, 'tape>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue