Compare commits

..

No commits in common. "ea96a0eb0ddaa6458e1a3099bf20bcca48e72db7" and "5bb7476af61409dd21578de85844a66bcc5ecf00" have entirely different histories.

2 changed files with 8 additions and 71 deletions

View File

@ -216,17 +216,5 @@ fn constrictor(c: &mut Criterion) {
}
}
fn clone(c: &mut Criterion) {
let request = create_standard_start_request([
Coord { x: 1, y: 1 },
Coord { x: 9, y: 1 },
Coord { x: 1, y: 9 },
Coord { x: 9, y: 9 },
]);
let board = Board::from(&request);
c.bench_function("clone", |b| b.iter(|| board.clone()));
}
criterion_group!(benches, standard, constrictor, clone);
criterion_group!(benches, standard, constrictor);
criterion_main!(benches);

View File

@ -1,9 +1,4 @@
use std::{
collections::VecDeque,
fmt::Display,
num::NonZeroUsize,
ops::{Deref, DerefMut},
};
use std::{collections::VecDeque, fmt::Display};
use bitvec::prelude::*;
use log::{error, warn};
@ -11,52 +6,6 @@ use rand::prelude::*;
use super::{wire::Request, Coord, Direction};
#[derive(Debug, PartialEq, Eq, Clone)]
enum SmallBitBox {
Stack {
storage: BitArr!(for Self::STACK_BITS),
len: NonZeroUsize,
},
Heap(BitBox),
}
impl SmallBitBox {
const STACK_BITS: usize = usize::BITS as usize * 3;
fn new(initial: bool, len: usize) -> Self {
if let len @ 1..Self::STACK_BITS = len {
let Some(len) = NonZeroUsize::new(len) else {
unreachable!()
};
let mut storage = BitArray::ZERO;
storage.fill(initial);
Self::Stack { storage, len }
} else {
Self::Heap(bitbox![u8::from(initial); len])
}
}
}
impl Deref for SmallBitBox {
type Target = BitSlice;
fn deref(&self) -> &Self::Target {
match self {
Self::Stack { storage, len } => &storage[..len.get()],
Self::Heap(bit_box) => bit_box,
}
}
}
impl DerefMut for SmallBitBox {
fn deref_mut(&mut self) -> &mut Self::Target {
match self {
Self::Stack { storage, len } => &mut storage[..len.get()],
Self::Heap(bit_box) => bit_box,
}
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Board {
width: u8,
@ -65,9 +14,9 @@ pub struct Board {
food_spawn_chance: u8,
min_food: u16,
turn: u32,
food: SmallBitBox,
hazard: SmallBitBox,
free: SmallBitBox,
food: BitBox,
hazard: BitBox,
free: BitBox,
snakes: Vec<Snake>,
constrictor: bool,
}
@ -84,9 +33,9 @@ impl From<&Request> for Board {
food_spawn_chance: value.game.ruleset.settings.food_spawn_chance,
min_food: value.game.ruleset.settings.minimum_food,
turn: value.turn,
food: SmallBitBox::new(false, fields),
hazard: SmallBitBox::new(false, fields),
free: SmallBitBox::new(true, fields),
food: bitbox![0; fields],
hazard: bitbox![0; fields],
free: bitbox![1; fields],
snakes: Vec::with_capacity(value.board.snakes.len()),
constrictor: value.game.ruleset.name == "constrictor",
};