Revert "stdlib: change sort() and sorted() into methods"

This reverts commits r27885, r27876.  It looks like they broke iOS on
arm64.

Swift SVN r27893
This commit is contained in:
Dmitri Hrybenko
2015-04-28 23:58:50 +00:00
parent 17e8328ae4
commit 4d197dc5b2
7 changed files with 23 additions and 606 deletions

View File

@@ -114,15 +114,15 @@ partitionDocComment = """\
/// Only returns `range.endIndex` when `self` is empty."""
orderingRequirementForPredicate = """\
/// Requires: `isOrderedBefore` is a
/// [strict weak ordering](http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings)
/// over the elements in `self`."""
/// Requires: `isOrderedBefore` is a `strict weak ordering
/// <http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings>`__
/// over `self`."""
orderingRequirementForComparable = """\
/// Requires: The less-than operator (`func <`) defined in the `Comparable`
/// conformance is a
/// [strict weak ordering](http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings)
/// over the elements in `self`."""
/// conformance is a `strict weak ordering
/// <http://en.wikipedia.org/wiki/Strict_weak_order#Strict_weak_orderings>`__
/// over `self`."""
}%
@@ -150,108 +150,3 @@ ${orderingRequirementForPredicate}
}
}
//===----------------------------------------------------------------------===//
// sort()
//===----------------------------------------------------------------------===//
%{
sortDocCommentForPredicate = """\
/// Return an `Array` containing the sorted elements of `source`
/// according to `isOrderedBefore`."""
sortDocCommentForComparable = """\
/// Return an `Array` containing the sorted elements of `source`."""
sortInPlaceDocCommentForPredicate = """\
/// Sort `self` in-place according to `isOrderedBefore`."""
sortInPlaceDocCommentForComparable = """\
/// Sort `self` in-place."""
sortIsUnstableForPredicate = """\
/// The sorting algorithm is not stable (can change the relative order of
/// elements for which `isOrderedBefore` does not establish an order)."""
sortIsUnstableForComparable = """\
/// The sorting algorithm is not stable (can change the relative order of
/// elements that compare equal)."""
}%
extension SequenceType where Self.Generator.Element : Comparable {
${sortDocCommentForComparable}
///
${sortIsUnstableForComparable}
///
${orderingRequirementForComparable}
final public func _prext_sort() -> [Generator.Element] {
var result = ContiguousArray(self)
result._prext_sortInPlace()
return Array(result)
}
}
extension SequenceType {
${sortDocCommentForPredicate}
///
${sortIsUnstableForPredicate}
///
${orderingRequirementForPredicate}
final public func _prext_sort(
@noescape isOrderedBefore: (Generator.Element, Generator.Element) -> Bool
) -> [Generator.Element] {
var result = ContiguousArray(self)
result._prext_sortInPlace(isOrderedBefore)
return Array(result)
}
}
extension MutableCollectionType
where
Self.Index : RandomAccessIndexType,
Self.Generator.Element : Comparable {
${sortInPlaceDocCommentForComparable}
///
${sortIsUnstableForComparable}
///
${orderingRequirementForComparable}
final public mutating func _prext_sortInPlace() {
let didSortUnsafeBuffer: Void? =
_withUnsafeMutableBufferPointerIfSupported {
(bufferPointer) -> () in
bufferPointer._prext_sortInPlace()
return ()
}
if didSortUnsafeBuffer == nil {
_introSort(&self, self._prext_indices)
}
}
}
extension MutableCollectionType where Self.Index : RandomAccessIndexType {
${sortInPlaceDocCommentForPredicate}
///
${sortIsUnstableForPredicate}
///
${orderingRequirementForPredicate}
final public mutating func _prext_sortInPlace(
@noescape isOrderedBefore: (Generator.Element, Generator.Element) -> Bool
) {
let didSortUnsafeBuffer: Void? =
_withUnsafeMutableBufferPointerIfSupported {
(bufferPointer) -> () in
bufferPointer._prext_sortInPlace(isOrderedBefore)
return ()
}
if didSortUnsafeBuffer == nil {
typealias IsOrderedBefore =
(Generator.Element, Generator.Element) -> Bool
let escapableIsOrderedBefore =
unsafeBitCast(isOrderedBefore, IsOrderedBefore.self)
_introSort(&self, self._prext_indices, escapableIsOrderedBefore)
}
}
}