speed up sorting for Stream

This should help to start playback a bit faster.
This commit is contained in:
Toni Förster
2024-05-19 12:39:47 +02:00
parent 90777d91f6
commit fa09b2021c
2 changed files with 16 additions and 15 deletions

View File

@@ -196,11 +196,13 @@ extension PlayerModel {
}
}
func streamsSorter(_ lhs: Stream, _ rhs: Stream) -> Bool {
if lhs.resolution.isNil || rhs.resolution.isNil {
func streamsSorter(lhs: Stream, rhs: Stream) -> Bool {
// Use optional chaining to simplify nil handling
guard let lhsRes = lhs.resolution?.height, let rhsRes = rhs.resolution?.height else {
return lhs.kind < rhs.kind
}
return lhs.kind == rhs.kind ? (lhs.resolution.height > rhs.resolution.height) : (lhs.kind < rhs.kind)
// Compare either kind or resolution based on conditions
return lhs.kind == rhs.kind ? (lhsRes > rhsRes) : (lhs.kind < rhs.kind)
}
}