Skip to content

Commit

Permalink
Copy to stack instead of cloning on the heap
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Sep 18, 2022
1 parent c024207 commit f124fd1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/core/src/blocks/redstone/redstone_wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::blocks::{
};
use crate::world::World;
use std::collections::HashMap;
use std::convert::TryInto;
use std::str::FromStr;

impl Block {
Expand Down Expand Up @@ -633,16 +634,18 @@ impl RedstoneWireTurbo {
if self.nodes[upd1.index].neighbors.is_none() {
self.identify_neighbors(world, upd1);
}
// FIXME: Get rid of this nasty clone
let neighbors = self.nodes[upd1.index].neighbors.clone().unwrap();

let neighbors: [NodeId; 24] = self.nodes[upd1.index].neighbors.as_ref().unwrap()[0..24]
.try_into()
.unwrap();

let layer1 = layer + 1;

for neighbor_id in &neighbors[0..24] {
for neighbor_id in neighbors {
let neighbor = &mut self.nodes[neighbor_id.index];
if layer1 > neighbor.layer {
neighbor.layer = layer1;
self.update_queue[1].push(*neighbor_id);
self.update_queue[1].push(neighbor_id);
}
}

Expand Down

0 comments on commit f124fd1

Please sign in to comment.