mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-22 04:10:39 +00:00
[minmax] Do nothing for empty suffix/prefix. (#202)
It's a semantical noop but slightly more efficient for the case when max/min is requested for an empty Collection.
This commit is contained in:
1 parent
bcd4f369ac
commit
dd4e0e70ff
1 file changed
+10
-10
@@ -256,13 +256,13 @@ extension Collection {
|
||||
"""
|
||||
)
|
||||
|
||||
// Do nothing if we're prefixing nothing.
|
||||
guard count > 0 else {
|
||||
return []
|
||||
}
|
||||
|
||||
// Make sure we are within bounds.
|
||||
let prefixCount = Swift.min(count, self.count)
|
||||
|
||||
// Do nothing if we're prefixing nothing.
|
||||
guard prefixCount > 0 else {
|
||||
return []
|
||||
}
|
||||
|
||||
// If we're attempting to prefix more than 10% of the collection, it's
|
||||
// faster to sort everything.
|
||||
@@ -310,13 +310,13 @@ extension Collection {
|
||||
"""
|
||||
)
|
||||
|
||||
// Do nothing if we're suffixing nothing.
|
||||
guard count > 0 else {
|
||||
return []
|
||||
}
|
||||
|
||||
// Make sure we are within bounds.
|
||||
let suffixCount = Swift.min(count, self.count)
|
||||
|
||||
// Do nothing if we're suffixing nothing.
|
||||
guard suffixCount > 0 else {
|
||||
return []
|
||||
}
|
||||
|
||||
// If we're attempting to prefix more than 10% of the collection, it's
|
||||
// faster to sort everything.
|
||||
|
||||
Reference in new issue
Block a user