diff --git a/crates/bevy_reflect/src/list.rs b/crates/bevy_reflect/src/list.rs index 6e487eb24e607e..936cd6704489e7 100644 --- a/crates/bevy_reflect/src/list.rs +++ b/crates/bevy_reflect/src/list.rs @@ -158,21 +158,21 @@ pub fn list_apply(a: &mut L, b: &dyn Reflect) { #[inline] pub fn list_partial_eq(a: &L, b: &dyn Reflect) -> Option { - Some(if let ReflectRef::List(list_value) = b.reflect_ref() { - if a.len() == list_value.len() { - for (a_value, b_value) in a.iter().zip(list_value.iter()) { - match a_value.partial_eq(b_value) { - Some(true) => {} - Some(false) => return Some(false), - None => return Some(false), - } - } + let list = if let ReflectRef::List(list) = b.reflect_ref() { + list + } else { + return Some(false); + }; + + if a.len() != list.len() { + return Some(false); + } - true - } else { - false + for (a_value, b_value) in a.iter().zip(list.iter()) { + if let Some(false) | None = a_value.partial_eq(b_value) { + return Some(false); } - } else { - false - }) + } + + Some(true) } diff --git a/crates/bevy_reflect/src/map.rs b/crates/bevy_reflect/src/map.rs index 5c9ca1c715bcad..1931b13ae1119d 100644 --- a/crates/bevy_reflect/src/map.rs +++ b/crates/bevy_reflect/src/map.rs @@ -160,25 +160,25 @@ impl<'a> Iterator for MapIter<'a> { #[inline] pub fn map_partial_eq(a: &M, b: &dyn Reflect) -> Option { - Some(if let ReflectRef::Map(map_value) = b.reflect_ref() { - if a.len() == map_value.len() { - for (key, value) in a.iter() { - if let Some(map_value) = map_value.get(key) { - match value.partial_eq(map_value) { - Some(true) => {} - Some(false) => return Some(false), - None => return Some(false), - } - } else { - return Some(false); - } - } + let map = if let ReflectRef::Map(map) = b.reflect_ref() { + map + } else { + return Some(false); + }; + + if a.len() != map.len() { + return Some(false); + } - true + for (key, value) in a.iter() { + if let Some(map_value) = map.get(key) { + if let Some(false) | None = value.partial_eq(map_value) { + return Some(false); + } } else { - false + return Some(false); } - } else { - false - }) + } + + Some(true) } diff --git a/crates/bevy_reflect/src/struct_trait.rs b/crates/bevy_reflect/src/struct_trait.rs index 753474b2d1ae3e..9d38838dcccc7a 100644 --- a/crates/bevy_reflect/src/struct_trait.rs +++ b/crates/bevy_reflect/src/struct_trait.rs @@ -231,26 +231,26 @@ impl Reflect for DynamicStruct { #[inline] pub fn struct_partial_eq(a: &S, b: &dyn Reflect) -> Option { - Some(if let ReflectRef::Struct(struct_value) = b.reflect_ref() { - if a.field_len() == struct_value.field_len() { - for (i, value) in struct_value.iter_fields().enumerate() { - let name = struct_value.name_at(i).unwrap(); - if let Some(field_value) = a.field(name) { - match field_value.partial_eq(value) { - Some(true) => {} - Some(false) => return Some(false), - None => return Some(false), - } - } else { - return Some(false); - } - } + let struct_value = if let ReflectRef::Struct(struct_value) = b.reflect_ref() { + struct_value + } else { + return Some(false); + }; - true + if a.field_len() != struct_value.field_len() { + return Some(false); + } + + for (i, value) in struct_value.iter_fields().enumerate() { + let name = struct_value.name_at(i).unwrap(); + if let Some(field_value) = a.field(name) { + if let Some(false) | None = field_value.partial_eq(value) { + return Some(false); + } } else { - false + return Some(false); } - } else { - false - }) + } + + Some(true) } diff --git a/crates/bevy_reflect/src/tuple_struct.rs b/crates/bevy_reflect/src/tuple_struct.rs index ce5735dd2a9de7..4b2c338ab8f6a9 100644 --- a/crates/bevy_reflect/src/tuple_struct.rs +++ b/crates/bevy_reflect/src/tuple_struct.rs @@ -186,27 +186,25 @@ impl Reflect for DynamicTupleStruct { #[inline] pub fn tuple_struct_partial_eq(a: &S, b: &dyn Reflect) -> Option { - Some( - if let ReflectRef::TupleStruct(tuple_struct) = b.reflect_ref() { - if a.field_len() == tuple_struct.field_len() { - for (i, value) in tuple_struct.iter_fields().enumerate() { - if let Some(field_value) = a.field(i) { - match field_value.partial_eq(value) { - Some(true) => {} - Some(false) => return Some(false), - None => return Some(false), - } - } else { - return Some(false); - } - } + let tuple_struct = if let ReflectRef::TupleStruct(tuple_struct) = b.reflect_ref() { + tuple_struct + } else { + return Some(false); + }; + + if a.field_len() != tuple_struct.field_len() { + return Some(false); + } - true - } else { - false + for (i, value) in tuple_struct.iter_fields().enumerate() { + if let Some(field_value) = a.field(i) { + if let Some(false) | None = field_value.partial_eq(value) { + return Some(false); } } else { - false - }, - ) + return Some(false); + } + } + + Some(true) }