Replace map + unwrap_or(true) with is_none_or (#17070)

# Objective

Reduce all varieties of `my_maybe.map(|x| x.is_true).unwrap_or(true)`
using `is_none_or`.
This commit is contained in:
ickshonpe 2024-12-31 20:17:03 +00:00 committed by GitHub
parent d502796a41
commit c73daea341
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 13 additions and 30 deletions

View File

@ -233,8 +233,7 @@ impl<'w, 's, T: Component> RemovedComponents<'w, 's, T> {
/// Returns `true` if there are no events available to read.
pub fn is_empty(&self) -> bool {
self.events()
.map(|events| self.reader.is_empty(events))
.unwrap_or(true)
.is_none_or(|events| self.reader.is_empty(events))
}
/// Consumes all available events.

View File

@ -139,10 +139,10 @@ impl<'w, 's, D: QueryData, F: QueryFilter> HierarchyQueryExt<'w, 's, D, F> for Q
{
self.iter_descendants_depth_first(entity).filter(|entity| {
self.get(*entity)
.ok()
// These are leaf nodes if they have the `Children` component but it's empty
.map(|children| children.is_empty())
// Or if they don't have the `Children` component at all
.unwrap_or(true)
.is_none_or(|children| children.is_empty())
})
}

View File

@ -99,10 +99,7 @@ pub fn update_hits(
let entity_layers = layers.get(entity).cloned().unwrap_or_default();
let render_layers_match = cam_layers.intersects(&entity_layers);
let is_pickable = pickables
.get(entity)
.map(|p| p.is_hoverable)
.unwrap_or(true);
let is_pickable = pickables.get(entity).ok().is_none_or(|p| p.is_hoverable);
marker_requirement && render_layers_match && is_pickable
},

View File

@ -89,10 +89,7 @@ pub(crate) struct FromReflectAttrs {
impl FromReflectAttrs {
/// Returns true if `FromReflect` should be automatically derived as part of the `Reflect` derive.
pub fn should_auto_derive(&self) -> bool {
self.auto_derive
.as_ref()
.map(LitBool::value)
.unwrap_or(true)
self.auto_derive.as_ref().is_none_or(LitBool::value)
}
}
@ -112,10 +109,7 @@ pub(crate) struct TypePathAttrs {
impl TypePathAttrs {
/// Returns true if `TypePath` should be automatically derived as part of the `Reflect` derive.
pub fn should_auto_derive(&self) -> bool {
self.auto_derive
.as_ref()
.map(LitBool::value)
.unwrap_or(true)
self.auto_derive.as_ref().is_none_or(LitBool::value)
}
}

View File

@ -375,12 +375,12 @@ impl SceneSpawner {
// the scene parent
if !world
.get_entity(entity)
.ok()
// This will filter only the scene root entity, as all other from the
// scene have a parent
.map(|entity| entity.contains::<Parent>())
// Default is true so that it won't run on an entity that wouldn't exist anymore
// Entities that wouldn't exist anymore are also skipped
// this case shouldn't happen anyway
.unwrap_or(true)
.is_none_or(|entity| entity.contains::<Parent>())
{
world.entity_mut(parent).add_child(entity);
}

View File

@ -186,9 +186,7 @@ fn sprite_picking(
};
blocked = cursor_in_valid_pixels_of_sprite
&& picking_behavior
.map(|p| p.should_block_lower)
.unwrap_or(true);
&& picking_behavior.is_none_or(|p| p.should_block_lower);
cursor_in_valid_pixels_of_sprite.then(|| {
let hit_pos_world =

View File

@ -702,14 +702,9 @@ pub fn extract_text_sections(
rect,
});
if text_layout_info
.glyphs
.get(i + 1)
.map(|info| {
info.span_index != current_span || info.atlas_info.texture != atlas_info.texture
})
.unwrap_or(true)
{
if text_layout_info.glyphs.get(i + 1).is_none_or(|info| {
info.span_index != current_span || info.atlas_info.texture != atlas_info.texture
}) {
let id = commands.spawn(TemporaryRenderEntity).id();
extracted_uinodes.uinodes.insert(