@@ -337,6 +337,7 @@ extension MutableCollection where Self: BidirectionalCollection {
337
337
/// - Precondition: `buffer` must point to a region of memory at least as large
338
338
/// as `min(mid - lo, hi - mid)`.
339
339
/// - Postcondition: `lo..<hi` is sorted according to `areInIncreasingOrder`.
340
+ @discardableResult
340
341
@inlinable
341
342
internal func _merge< Element> (
342
343
low: UnsafeMutablePointer < Element > ,
@@ -439,7 +440,6 @@ internal func _merge<Element>(
439
440
}
440
441
}
441
442
442
- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
443
443
return true
444
444
}
445
445
@@ -512,6 +512,7 @@ extension UnsafeMutableBufferPointer {
512
512
/// - Precondition: `runs.count > 1` and `i > 0`
513
513
/// - Precondition: `buffer` must have at least
514
514
/// `min(runs[i].count, runs[i - 1].count)` uninitialized elements.
515
+ @discardableResult
515
516
@inlinable
516
517
public mutating func _mergeRuns(
517
518
_ runs: inout [ Range < Index > ] ,
@@ -524,7 +525,7 @@ extension UnsafeMutableBufferPointer {
524
525
let middle = runs [ i] . lowerBound
525
526
let high = runs [ i] . upperBound
526
527
527
- let result = try _merge (
528
+ try _merge (
528
529
low: baseAddress! + low,
529
530
mid: baseAddress! + middle,
530
531
high: baseAddress! + high,
@@ -534,8 +535,7 @@ extension UnsafeMutableBufferPointer {
534
535
runs [ i - 1 ] = low..< high
535
536
runs. remove ( at: i)
536
537
537
- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
538
- return result
538
+ return true
539
539
}
540
540
541
541
/// Merges upper elements of `runs` until the required invariants are
@@ -545,6 +545,7 @@ extension UnsafeMutableBufferPointer {
545
545
/// `min(runs[i].count, runs[i - 1].count)` uninitialized elements.
546
546
/// - Precondition: The ranges in `runs` must be consecutive, such that for
547
547
/// any i, `runs[i].upperBound == runs[i + 1].lowerBound`.
548
+ @discardableResult
548
549
@inlinable
549
550
public mutating func _mergeTopRuns(
550
551
_ runs: inout [ Range < Index > ] ,
@@ -571,9 +572,6 @@ extension UnsafeMutableBufferPointer {
571
572
// If W > X + Y, X > Y + Z, and Y > Z, then the invariants are satisfied
572
573
// for the entirety of `runs`.
573
574
574
- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
575
- var result = true
576
-
577
575
// The invariant is always in place for a single element.
578
576
while runs. count > 1 {
579
577
var lastIndex = runs. count - 1
@@ -607,11 +605,11 @@ extension UnsafeMutableBufferPointer {
607
605
}
608
606
609
607
// Merge the runs at `i` and `i - 1`.
610
- result = try result && _mergeRuns (
608
+ try _mergeRuns (
611
609
& runs, at: lastIndex, buffer: buffer, by: areInIncreasingOrder)
612
610
}
613
611
614
- return result
612
+ return true
615
613
}
616
614
617
615
/// Merges elements of `runs` until only one run remains.
@@ -620,19 +618,19 @@ extension UnsafeMutableBufferPointer {
620
618
/// `min(runs[i].count, runs[i - 1].count)` uninitialized elements.
621
619
/// - Precondition: The ranges in `runs` must be consecutive, such that for
622
620
/// any i, `runs[i].upperBound == runs[i + 1].lowerBound`.
621
+ @discardableResult
623
622
@inlinable
624
623
public mutating func _finalizeRuns(
625
624
_ runs: inout [ Range < Index > ] ,
626
625
buffer: UnsafeMutablePointer < Element > ,
627
626
by areInIncreasingOrder: ( Element , Element ) throws -> Bool
628
627
) rethrows -> Bool {
629
- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
630
- var result = true
631
628
while runs. count > 1 {
632
- result = try result && _mergeRuns (
629
+ try _mergeRuns (
633
630
& runs, at: runs. count - 1 , buffer: buffer, by: areInIncreasingOrder)
634
631
}
635
- return result
632
+
633
+ return true
636
634
}
637
635
638
636
/// Sorts the elements of this buffer according to `areInIncreasingOrder`,
@@ -651,9 +649,6 @@ extension UnsafeMutableBufferPointer {
651
649
return
652
650
}
653
651
654
- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
655
- var result = true
656
-
657
652
// Use array's allocating initializer to create a temporary buffer---this
658
653
// keeps the buffer allocation going through the same tail-allocated path
659
654
// as other allocating methods.
@@ -685,17 +680,14 @@ extension UnsafeMutableBufferPointer {
685
680
// Append this run and merge down as needed to maintain the `runs`
686
681
// invariants.
687
682
runs. append ( start..< end)
688
- result = try result && _mergeTopRuns (
683
+ try _mergeTopRuns (
689
684
& runs, buffer: buffer. baseAddress!, by: areInIncreasingOrder)
690
685
start = end
691
686
}
692
687
693
- result = try result && _finalizeRuns (
688
+ try _finalizeRuns (
694
689
& runs, buffer: buffer. baseAddress!, by: areInIncreasingOrder)
695
690
_internalInvariant ( runs. count == 1 , " Didn't complete final merge " )
696
691
}
697
-
698
- // FIXME: Remove this, it works around SR-14750 (rdar://45044610)
699
- _precondition ( result)
700
692
}
701
693
}
0 commit comments