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

[stdlib] Switch to a stable sort algorithm #19717

Merged
merged 16 commits into from Nov 7, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -320,14 +320,21 @@ extension MutableCollection where Self : BidirectionalCollection {
) rethrows -> Index {
let maybeOffset = try _withUnsafeMutableBufferPointerIfSupported {
(bufferPointer) -> Int in
let unsafeBufferPivot = try bufferPointer.partition(
let unsafeBufferPivot = try bufferPointer._partitionImpl(
by: belongsInSecondPartition)
return unsafeBufferPivot - bufferPointer.startIndex
}
if let offset = maybeOffset {
return index(startIndex, offsetBy: numericCast(offset))
return index(startIndex, offsetBy: offset)
} else {
return try _partitionImpl(by: belongsInSecondPartition)
}

}

@usableFromInline
internal mutating func _partitionImpl(
by belongsInSecondPartition: (Element) throws -> Bool
) rethrows -> Index {
var lo = startIndex
var hi = endIndex

Large diffs are not rendered by default.

@@ -408,6 +408,13 @@ extension Unsafe${Mutable}BufferPointer {
count = other.count
}

@inlinable
public mutating func _withUnsafeMutableBufferPointerIfSupported<R>(
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
) rethrows -> R? {
return try body(&self)
}

% else:

/// Creates an immutable typed buffer pointer referencing the same memory as the
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.