[Optimization] Improve readability (#345)

This commit is contained in:
imizao 2023-03-22 14:57:48 +08:00 committed by GitHub
parent 5a96eea6ba
commit e99c5eaa24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -334,14 +334,9 @@ impl ConwayGrid {
}
fn grid_idx<I: std::convert::TryInto<usize>>(&self, x: I, y: I) -> Option<usize> {
if let (Ok(x), Ok(y)) = (x.try_into(), y.try_into()) {
if x < self.width && y < self.height {
Some(x + y * self.width)
} else {
None
}
} else {
None
match (x.try_into(), y.try_into()) {
(Ok(x), Ok(y)) if x < self.width && y < self.height => Some(x + y * self.width),
_ => None,
}
}
}