Skip to content

[stdlib][Gardening] Delete few redundant numericCasts #13684

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

Merged
merged 1 commit into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/public/core/Arrays.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ extension ${Self} {

let oldCount = _buffer.count
let eraseCount = subrange.count
let insertCount = numericCast(newElements.count) as Int
let insertCount = newElements.count
let growth = insertCount - eraseCount

if _buffer.requestUniqueMutableBackingBuffer(
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/BidirectionalCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ extension BidirectionalCollection where SubSequence == Self {
public mutating func removeLast(_ n: Int) {
if n == 0 { return }
_precondition(n >= 0, "Number of elements to remove should be non-negative")
_precondition(count >= numericCast(n),
_precondition(count >= n,
"Can't remove more items from a collection than it contains")
self = self[startIndex..<index(endIndex, offsetBy: numericCast(-n))]
self = self[startIndex..<index(endIndex, offsetBy: -n)]
}
}

Expand Down Expand Up @@ -275,7 +275,7 @@ extension BidirectionalCollection {
n >= 0, "Can't drop a negative number of elements from a collection")
let end = index(
endIndex,
offsetBy: numericCast(-n),
offsetBy: -n,
limitedBy: startIndex) ?? startIndex
return self[startIndex..<end]
}
Expand Down Expand Up @@ -305,7 +305,7 @@ extension BidirectionalCollection {
"Can't take a suffix of negative length from a collection")
let start = index(
endIndex,
offsetBy: numericCast(-maxLength),
offsetBy: -maxLength,
limitedBy: startIndex) ?? startIndex
return self[start..<endIndex]
}
Expand Down
26 changes: 13 additions & 13 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ extension Collection {
@_inlineable
public var underestimatedCount: Int {
// TODO: swift-3-indexing-model - review the following
return numericCast(count)
return count
}

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

var result = ContiguousArray<T>()
result.reserveCapacity(count)
result.reserveCapacity(n)

var i = self.startIndex

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

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

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

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

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

Expand Down