Skip to content

Commit

Permalink
[Optimization] Improve readability (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
imizao committed Mar 22, 2023
1 parent 5a96eea commit e99c5ea
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions examples/conway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}

0 comments on commit e99c5ea

Please sign in to comment.