Skip to content

Commit b582683

Browse files
committed
[stdlib] Use unsigned arithmetic in partition
1 parent 5d42113 commit b582683

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

stdlib/public/core/Sort.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ func _partition<C>(
165165

166166
// Sort the first, middle, and last elements, then use the middle value
167167
// as the pivot for the partition.
168-
let half = elements.distance(from: lo, to: hi) / 2
169-
let mid = elements.index(lo, offsetBy: half)
168+
let half = numericCast(elements.distance(from: lo, to: hi)) as UInt / 2
169+
let mid = elements.index(lo, offsetBy: numericCast(half))
170170
_sort3(&elements, lo, mid, hi
171171
${", by: areInIncreasingOrder" if p else ""})
172172
let pivot = elements[mid]

0 commit comments

Comments
 (0)