world/layer: avoid iproduct-based iterator in inner loop

iproduct iterators are fairly slow. As the iterator implementation is
now unused, it is removed as well.
This commit is contained in:
Matthias Schiffer 2023-05-10 00:48:53 +02:00
parent 31eb92864c
commit 42cb342749
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
2 changed files with 17 additions and 27 deletions

View file

@ -73,20 +73,6 @@ impl LayerBlockCoords {
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
pub struct LayerBlockArray<T>(pub [[T; BLOCKS_PER_CHUNK]; BLOCKS_PER_CHUNK]);
impl<T> LayerBlockArray<T> {
pub fn keys() -> impl Iterator<Item = LayerBlockCoords> + Clone + Debug {
iproduct!(BlockZ::iter(), BlockX::iter()).map(|(z, x)| LayerBlockCoords { x, z })
}
pub fn values(&self) -> impl Iterator<Item = &T> + Clone + Debug {
Self::keys().map(|k| &self[k])
}
pub fn iter(&self) -> impl Iterator<Item = (LayerBlockCoords, &T)> + Clone + Debug {
Self::keys().map(|k| (k, &self[k]))
}
}
impl<T> Index<LayerBlockCoords> for LayerBlockArray<T> {
type Output = T;

View file

@ -111,21 +111,25 @@ pub fn top_layer(chunk: &Chunk) -> Result<Option<LayerData>> {
for section in chunk.sections().rev() {
for y in BlockY::iter().rev() {
for xz in LayerBlockArray::<()>::keys() {
let mut entry = ret.entry(xz);
if entry.done() {
continue;
}
for z in BlockZ::iter() {
for x in BlockX::iter() {
let xz = LayerBlockCoords { x, z };
let coords = SectionBlockCoords { xz, y };
if !entry.fill(section, coords)? {
continue;
}
let mut entry = ret.entry(xz);
if entry.done() {
continue;
}
assert!(entry.done());
done += 1;
if done == N * N {
break;
let coords = SectionBlockCoords { xz, y };
if !entry.fill(section, coords)? {
continue;
}
assert!(entry.done());
done += 1;
if done == N * N {
break;
}
}
}
}