[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:
Taras Tsugrii authored and GitHub committed 2023-10-31 11:03:19 -05:00
1 parent bcd4f369ac
commit dd4e0e70ff
1 file changed
+10 -10
+10 -10
View File
@@ -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.