Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[minmax] Do nothing for empty suffix/prefix. #202

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Sources/Algorithms/MinMax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down