Skip to content

Commit c7e05cb

Browse files
[stdlib][Gardening] Delete few rogue IndexDistance numericCasts that slipped through (#13684)
1 parent d326d3c commit c7e05cb

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

stdlib/public/core/Arrays.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@ extension ${Self} {
19451945

19461946
let oldCount = _buffer.count
19471947
let eraseCount = subrange.count
1948-
let insertCount = numericCast(newElements.count) as Int
1948+
let insertCount = newElements.count
19491949
let growth = insertCount - eraseCount
19501950

19511951
if _buffer.requestUniqueMutableBackingBuffer(

stdlib/public/core/BidirectionalCollection.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ extension BidirectionalCollection where SubSequence == Self {
245245
public mutating func removeLast(_ n: Int) {
246246
if n == 0 { return }
247247
_precondition(n >= 0, "Number of elements to remove should be non-negative")
248-
_precondition(count >= numericCast(n),
248+
_precondition(count >= n,
249249
"Can't remove more items from a collection than it contains")
250-
self = self[startIndex..<index(endIndex, offsetBy: numericCast(-n))]
250+
self = self[startIndex..<index(endIndex, offsetBy: -n)]
251251
}
252252
}
253253

@@ -275,7 +275,7 @@ extension BidirectionalCollection {
275275
n >= 0, "Can't drop a negative number of elements from a collection")
276276
let end = index(
277277
endIndex,
278-
offsetBy: numericCast(-n),
278+
offsetBy: -n,
279279
limitedBy: startIndex) ?? startIndex
280280
return self[startIndex..<end]
281281
}
@@ -305,7 +305,7 @@ extension BidirectionalCollection {
305305
"Can't take a suffix of negative length from a collection")
306306
let start = index(
307307
endIndex,
308-
offsetBy: numericCast(-maxLength),
308+
offsetBy: -maxLength,
309309
limitedBy: startIndex) ?? startIndex
310310
return self[start..<endIndex]
311311
}

stdlib/public/core/Collection.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ extension Collection {
11501150
@_inlineable
11511151
public var underestimatedCount: Int {
11521152
// TODO: swift-3-indexing-model - review the following
1153-
return numericCast(count)
1153+
return count
11541154
}
11551155

11561156
/// The number of elements in the collection.
@@ -1213,17 +1213,17 @@ extension Collection {
12131213
_ transform: (Element) throws -> T
12141214
) rethrows -> [T] {
12151215
// TODO: swift-3-indexing-model - review the following
1216-
let count: Int = numericCast(self.count)
1217-
if count == 0 {
1216+
let n = self.count
1217+
if n == 0 {
12181218
return []
12191219
}
12201220

12211221
var result = ContiguousArray<T>()
1222-
result.reserveCapacity(count)
1222+
result.reserveCapacity(n)
12231223

12241224
var i = self.startIndex
12251225

1226-
for _ in 0..<count {
1226+
for _ in 0..<n {
12271227
result.append(try transform(self[i]))
12281228
formIndex(after: &i)
12291229
}
@@ -1255,7 +1255,7 @@ extension Collection {
12551255
public func dropFirst(_ n: Int) -> SubSequence {
12561256
_precondition(n >= 0, "Can't drop a negative number of elements from a collection")
12571257
let start = index(startIndex,
1258-
offsetBy: numericCast(n), limitedBy: endIndex) ?? endIndex
1258+
offsetBy: n, limitedBy: endIndex) ?? endIndex
12591259
return self[start..<endIndex]
12601260
}
12611261

@@ -1281,9 +1281,9 @@ extension Collection {
12811281
public func dropLast(_ n: Int) -> SubSequence {
12821282
_precondition(
12831283
n >= 0, "Can't drop a negative number of elements from a collection")
1284-
let amount = Swift.max(0, numericCast(count) - n)
1284+
let amount = Swift.max(0, count - n)
12851285
let end = index(startIndex,
1286-
offsetBy: numericCast(amount), limitedBy: endIndex) ?? endIndex
1286+
offsetBy: amount, limitedBy: endIndex) ?? endIndex
12871287
return self[startIndex..<end]
12881288
}
12891289

@@ -1329,7 +1329,7 @@ extension Collection {
13291329
maxLength >= 0,
13301330
"Can't take a prefix of negative length from a collection")
13311331
let end = index(startIndex,
1332-
offsetBy: numericCast(maxLength), limitedBy: endIndex) ?? endIndex
1332+
offsetBy: maxLength, limitedBy: endIndex) ?? endIndex
13331333
return self[startIndex..<end]
13341334
}
13351335

@@ -1376,9 +1376,9 @@ extension Collection {
13761376
_precondition(
13771377
maxLength >= 0,
13781378
"Can't take a suffix of negative length from a collection")
1379-
let amount = Swift.max(0, numericCast(count) - maxLength)
1379+
let amount = Swift.max(0, count - maxLength)
13801380
let start = index(startIndex,
1381-
offsetBy: numericCast(amount), limitedBy: endIndex) ?? endIndex
1381+
offsetBy: amount, limitedBy: endIndex) ?? endIndex
13821382
return self[start..<endIndex]
13831383
}
13841384

@@ -1677,9 +1677,9 @@ extension Collection where SubSequence == Self {
16771677
public mutating func removeFirst(_ n: Int) {
16781678
if n == 0 { return }
16791679
_precondition(n >= 0, "Number of elements to remove should be non-negative")
1680-
_precondition(count >= numericCast(n),
1680+
_precondition(count >= n,
16811681
"Can't remove more items from a collection than it contains")
1682-
self = self[index(startIndex, offsetBy: numericCast(n))..<endIndex]
1682+
self = self[index(startIndex, offsetBy: n)..<endIndex]
16831683
}
16841684
}
16851685

0 commit comments

Comments
 (0)