Skip to content

Commit

Permalink
chop some trees
Browse files Browse the repository at this point in the history
  • Loading branch information
cart committed Nov 27, 2020
1 parent a9d7df7 commit 9db8646
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 72 deletions.
30 changes: 15 additions & 15 deletions crates/bevy_reflect/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,21 @@ pub fn list_apply<L: List>(a: &mut L, b: &dyn Reflect) {

#[inline]
pub fn list_partial_eq<L: List>(a: &L, b: &dyn Reflect) -> Option<bool> {
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)
}
36 changes: 18 additions & 18 deletions crates/bevy_reflect/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,25 @@ impl<'a> Iterator for MapIter<'a> {

#[inline]
pub fn map_partial_eq<M: Map>(a: &M, b: &dyn Reflect) -> Option<bool> {
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)
}
38 changes: 19 additions & 19 deletions crates/bevy_reflect/src/struct_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,26 +231,26 @@ impl Reflect for DynamicStruct {

#[inline]
pub fn struct_partial_eq<S: Struct>(a: &S, b: &dyn Reflect) -> Option<bool> {
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)
}
38 changes: 18 additions & 20 deletions crates/bevy_reflect/src/tuple_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,25 @@ impl Reflect for DynamicTupleStruct {

#[inline]
pub fn tuple_struct_partial_eq<S: TupleStruct>(a: &S, b: &dyn Reflect) -> Option<bool> {
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)
}

0 comments on commit 9db8646

Please sign in to comment.