[core] Directly index the array of Squares with a given index
In Square::from_index_unchecked, instead of using TryFrom to convert the index to a square, just index directly into the Square::ALL array. This function is already marked unsafe.
This commit is contained in:
parent
1d8a0dc3a4
commit
481ae70698
1 changed files with 4 additions and 2 deletions
|
@ -115,7 +115,9 @@ macro_rules! range_bound_struct {
|
||||||
|
|
||||||
coordinate_enum!(
|
coordinate_enum!(
|
||||||
Direction,
|
Direction,
|
||||||
[North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest]
|
[
|
||||||
|
North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
impl Direction {
|
impl Direction {
|
||||||
|
@ -262,7 +264,7 @@ impl Square {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub unsafe fn from_index_unchecked(x: u8) -> Square {
|
pub unsafe fn from_index_unchecked(x: u8) -> Square {
|
||||||
debug_assert!((x as usize) < Self::NUM);
|
debug_assert!((x as usize) < Self::NUM);
|
||||||
Self::try_from(x).unwrap_unchecked()
|
Self::ALL[x as usize]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue