diff --git a/Sources/Algorithms/MinMax.swift b/Sources/Algorithms/MinMax.swift index 3bce4af5..ea6b5a7a 100644 --- a/Sources/Algorithms/MinMax.swift +++ b/Sources/Algorithms/MinMax.swift @@ -256,14 +256,14 @@ extension Collection { """ ) + // Make sure we are within bounds. + let prefixCount = Swift.min(count, self.count) + // Do nothing if we're prefixing nothing. - guard count > 0 else { + guard prefixCount > 0 else { return [] } - // Make sure we are within bounds. - let prefixCount = Swift.min(count, self.count) - // If we're attempting to prefix more than 10% of the collection, it's // faster to sort everything. guard prefixCount < (self.count / 10) else { @@ -310,14 +310,14 @@ extension Collection { """ ) + // Make sure we are within bounds. + let suffixCount = Swift.min(count, self.count) + // Do nothing if we're suffixing nothing. - guard count > 0 else { + guard suffixCount > 0 else { return [] } - // Make sure we are within bounds. - let suffixCount = Swift.min(count, self.count) - // If we're attempting to prefix more than 10% of the collection, it's // faster to sort everything. guard suffixCount < (self.count / 10) else {