bevy/crates/bevy_ecs/src
Vic b78efd339d
Simplify sort/max_by calls (#17048)
# Objective

Some sort calls and `Ord` impls are unnecessarily complex.

## Solution

Rewrite the "match on cmp, if equal do another cmp" as either a
comparison on tuples, or `Ordering::then_with`, depending on whether the
compare keys need construction.

`sort_by` -> `sort_by_key` when symmetrical. Do the same for
`min_by`/`max_by`.

Note that `total_cmp` can only work with `sort_by`, and not on tuples.

When sorting collected query results that contain
`Entity`/`MainEntity`/`RenderEntity` in their `QueryData`, with that
`Entity` in the sort key:
stable -> unstable sort (all queried entities are unique)

If key construction is not simple, switch to `sort_by_cached_key` when
possible.

Sorts that are only performed to discover the maximal element are
replaced by `max_by_key`.

Dedicated comparison functions and structs are removed where simple.

Derive `PartialOrd`/`Ord` when useful.

Misc. closure style inconsistencies.

## Testing
- Existing tests.
2024-12-30 22:59:36 +00:00
..
entity Fix random clippy warning (#17010) 2024-12-29 19:28:59 +00:00
event Refactor hierarchy-related commands to remove structs (#17029) 2024-12-30 20:58:03 +00:00
identifier Use en-us locale for typos (#16037) 2024-10-20 18:55:17 +00:00
observer Move some structs that impl Command to methods on World and EntityWorldMut (#16999) 2024-12-29 22:18:53 +00:00
query Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
reflect Move some structs that impl Command to methods on World and EntityWorldMut (#16999) 2024-12-29 22:18:53 +00:00
schedule Simplify sort/max_by calls (#17048) 2024-12-30 22:59:36 +00:00
storage Prevent creation of superfluous empty table (#16935) 2024-12-22 23:04:32 +00:00
system Refactor hierarchy-related commands to remove structs (#17029) 2024-12-30 20:58:03 +00:00
world Remove unsound Clone impl for EntityMutExcept (#17032) 2024-12-30 05:17:46 +00:00
archetype.rs Add no_std support to bevy_ecs (#16758) 2024-12-17 21:40:36 +00:00
batching.rs Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bundle.rs Add no_std support to bevy_ecs (#16758) 2024-12-17 21:40:36 +00:00
change_detection.rs Set panic as default fallible system param behavior (#16638) 2024-12-24 02:36:03 +00:00
component.rs Faster entity cloning (#16717) 2024-12-18 20:03:39 +00:00
intern.rs Remove OnceLock usage from bevy_ecs (#16870) 2024-12-17 22:42:42 +00:00
label.rs Add core and alloc over std Lints (#15281) 2024-09-27 00:59:59 +00:00
lib.rs impl EntityBorrow for more types (#16917) 2024-12-24 02:47:03 +00:00
name.rs Add no_std support to bevy_input (#16995) 2024-12-29 22:46:30 +00:00
removal_detection.rs Prefer Display over Debug (#16112) 2024-12-27 00:40:06 +00:00
result.rs Add no_std support to bevy_ecs (#16758) 2024-12-17 21:40:36 +00:00
traversal.rs Window picking (#16103) 2024-12-05 21:14:39 +00:00