reduce nesting in the sparse_set
module (#17066)
# Objective Just being fussy but I hate this `.map(|v| v.is_some()).unwrap_or(false)` stuff. ## Solution Reduce it using `and_then`. --------- Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
This commit is contained in:
parent
afed4e27d1
commit
2931e350b6
@ -50,7 +50,7 @@ macro_rules! impl_sparse_array {
|
||||
#[inline]
|
||||
pub fn contains(&self, index: I) -> bool {
|
||||
let index = index.sparse_set_index();
|
||||
self.values.get(index).map(|v| v.is_some()).unwrap_or(false)
|
||||
self.values.get(index).is_some_and(Option::is_some)
|
||||
}
|
||||
|
||||
/// Returns a reference to the value at `index`.
|
||||
@ -59,7 +59,7 @@ macro_rules! impl_sparse_array {
|
||||
#[inline]
|
||||
pub fn get(&self, index: I) -> Option<&V> {
|
||||
let index = index.sparse_set_index();
|
||||
self.values.get(index).map(|v| v.as_ref()).unwrap_or(None)
|
||||
self.values.get(index).and_then(Option::as_ref)
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -87,10 +87,7 @@ impl<I: SparseSetIndex, V> SparseArray<I, V> {
|
||||
#[inline]
|
||||
pub fn get_mut(&mut self, index: I) -> Option<&mut V> {
|
||||
let index = index.sparse_set_index();
|
||||
self.values
|
||||
.get_mut(index)
|
||||
.map(|v| v.as_mut())
|
||||
.unwrap_or(None)
|
||||
self.values.get_mut(index).and_then(Option::as_mut)
|
||||
}
|
||||
|
||||
/// Removes and returns the value stored at `index`.
|
||||
|
Loading…
Reference in New Issue
Block a user