Skip to content

Commit eaa141d

Browse files
committed
[minmax] Do nothing for empty suffix/prefix.
It's a semantical noop but slightly more efficient for the case when max/min is requested for an empty Collection.
1 parent fc8fdfd commit eaa141d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Sources/Algorithms/MinMax.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,14 @@ extension Collection {
310310
"""
311311
)
312312

313+
// Make sure we are within bounds.
314+
let suffixCount = Swift.min(count, self.count)
315+
313316
// Do nothing if we're suffixing nothing.
314-
guard count > 0 else {
317+
guard suffixCount > 0 else {
315318
return []
316319
}
317320

318-
// Make sure we are within bounds.
319-
let suffixCount = Swift.min(count, self.count)
320-
321321
// If we're attempting to prefix more than 10% of the collection, it's
322322
// faster to sort everything.
323323
guard suffixCount < (self.count / 10) else {

0 commit comments

Comments
 (0)