mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
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:
parent
31eb92864c
commit
42cb342749
2 changed files with 17 additions and 27 deletions
14
src/types.rs
14
src/types.rs
|
@ -73,20 +73,6 @@ impl LayerBlockCoords {
|
||||||
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
|
||||||
pub struct LayerBlockArray<T>(pub [[T; BLOCKS_PER_CHUNK]; BLOCKS_PER_CHUNK]);
|
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> {
|
impl<T> Index<LayerBlockCoords> for LayerBlockArray<T> {
|
||||||
type Output = T;
|
type Output = T;
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,10 @@ pub fn top_layer(chunk: &Chunk) -> Result<Option<LayerData>> {
|
||||||
|
|
||||||
for section in chunk.sections().rev() {
|
for section in chunk.sections().rev() {
|
||||||
for y in BlockY::iter().rev() {
|
for y in BlockY::iter().rev() {
|
||||||
for xz in LayerBlockArray::<()>::keys() {
|
for z in BlockZ::iter() {
|
||||||
|
for x in BlockX::iter() {
|
||||||
|
let xz = LayerBlockCoords { x, z };
|
||||||
|
|
||||||
let mut entry = ret.entry(xz);
|
let mut entry = ret.entry(xz);
|
||||||
if entry.done() {
|
if entry.done() {
|
||||||
continue;
|
continue;
|
||||||
|
@ -130,6 +133,7 @@ pub fn top_layer(chunk: &Chunk) -> Result<Option<LayerData>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Some(ret))
|
Ok(Some(ret))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue