Skip to content

Commit f6d8f82

Browse files
authored
Replace Index with Int where possible (apple#32)
1 parent b91621e commit f6d8f82

14 files changed

+109
-109
lines changed

Sources/DequeModule/Deque+MutableCollection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension Deque: MutableCollection {
2222
/// - Complexity: O(1) when this instance has a unique reference to its
2323
/// underlying storage; O(`count`) otherwise.
2424
@inlinable
25-
public mutating func swapAt(_ i: Index, _ j: Index) {
25+
public mutating func swapAt(_ i: Int, _ j: Int) {
2626
precondition(i >= 0 && i < count, "Index out of bounds")
2727
precondition(j >= 0 && j < count, "Index out of bounds")
2828
_storage.ensureUnique()

Sources/DequeModule/Deque+RandomAccessCollection.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension Deque: RandomAccessCollection {
2828
/// - Complexity: O(1)
2929
@inlinable
3030
@inline(__always)
31-
public var startIndex: Index { 0 }
31+
public var startIndex: Int { 0 }
3232

3333
/// The deque’s “past the end” position—that is, the position one greater than
3434
/// the last valid subscript argument.
@@ -39,7 +39,7 @@ extension Deque: RandomAccessCollection {
3939
/// - Complexity: O(1)
4040
@inlinable
4141
@inline(__always)
42-
public var endIndex: Index { count }
42+
public var endIndex: Int { count }
4343

4444
/// Returns the position immediately after the given index.
4545
///
@@ -51,7 +51,7 @@ extension Deque: RandomAccessCollection {
5151
/// - Complexity: O(1)
5252
@inlinable
5353
@inline(__always)
54-
public func index(after i: Index) -> Index {
54+
public func index(after i: Int) -> Int {
5555
// Note: Like `Array`, index manipulation methods on deques don't trap on
5656
// invalid indices. (Indices are still validated on element access.)
5757
return i + 1
@@ -65,7 +65,7 @@ extension Deque: RandomAccessCollection {
6565
/// - Complexity: O(1)
6666
@inlinable
6767
@inline(__always)
68-
public func formIndex(after i: inout Index) {
68+
public func formIndex(after i: inout Int) {
6969
// Note: Like `Array`, index manipulation methods on deques
7070
// don't trap on invalid indices.
7171
// (Indices are still validated on element access.)
@@ -82,7 +82,7 @@ extension Deque: RandomAccessCollection {
8282
/// - Complexity: O(1)
8383
@inlinable
8484
@inline(__always)
85-
public func index(before i: Index) -> Index {
85+
public func index(before i: Int) -> Int {
8686
// Note: Like `Array`, index manipulation methods on deques don't trap on
8787
// invalid indices. (Indices are still validated on element access.)
8888
return i - 1
@@ -95,7 +95,7 @@ extension Deque: RandomAccessCollection {
9595
/// - Complexity: O(1)
9696
@inlinable
9797
@inline(__always)
98-
public func formIndex(before i: inout Index) {
98+
public func formIndex(before i: inout Int) {
9999
// Note: Like `Array`, index manipulation methods on deques don't trap on
100100
// invalid indices. (Indices are still validated on element access.)
101101
i -= 1
@@ -118,7 +118,7 @@ extension Deque: RandomAccessCollection {
118118
/// - Complexity: O(1)
119119
@inlinable
120120
@inline(__always)
121-
public func index(_ i: Index, offsetBy distance: Int) -> Index {
121+
public func index(_ i: Int, offsetBy distance: Int) -> Int {
122122
// Note: Like `Array`, index manipulation methods on deques don't trap on
123123
// invalid indices. (Indices are still validated on element access.)
124124
return i + distance
@@ -170,7 +170,7 @@ extension Deque: RandomAccessCollection {
170170
/// - Complexity: O(1)
171171
@inlinable
172172
@inline(__always)
173-
public func distance(from start: Index, to end: Index) -> Int {
173+
public func distance(from start: Int, to end: Int) -> Int {
174174
// Note: Like `Array`, index manipulation method on deques
175175
// don't trap on invalid indices.
176176
// (Indices are still validated on element access.)
@@ -187,7 +187,7 @@ extension Deque: RandomAccessCollection {
187187
/// unless the deque’s storage is shared with another deque, in which case
188188
/// writing is O(`count`).
189189
@inlinable
190-
public subscript(index: Index) -> Element {
190+
public subscript(index: Int) -> Element {
191191
get {
192192
precondition(index >= 0 && index < count, "Index out of bounds")
193193
return _storage.read { $0.ptr(at: $0.slot(forOffset: index)).pointee }
@@ -228,7 +228,7 @@ extension Deque: RandomAccessCollection {
228228
/// The accessed slice uses the same indices for the same elements as the
229229
/// original collection.
230230
@inlinable
231-
public subscript(bounds: Range<Index>) -> Slice<Self> {
231+
public subscript(bounds: Range<Int>) -> Slice<Self> {
232232
get {
233233
precondition(bounds.lowerBound >= 0 && bounds.upperBound <= count,
234234
"Invalid bounds")

Sources/DequeModule/Deque+RangeReplaceableCollection.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension Deque: RangeReplaceableCollection {
4747
/// `subrange`.
4848
@inlinable
4949
public mutating func replaceSubrange<C: Collection>(
50-
_ subrange: Range<Index>,
50+
_ subrange: Range<Int>,
5151
with newElements: __owned C
5252
) where C.Element == Element {
5353
precondition(subrange.lowerBound >= 0 && subrange.upperBound <= count, "Index range out of bounds")
@@ -272,7 +272,7 @@ extension Deque: RangeReplaceableCollection {
272272
/// elements that need to be moved. When inserting at the start or the end,
273273
/// this reduces the complexity to amortized O(1).
274274
@inlinable
275-
public mutating func insert(_ newElement: Element, at index: Index) {
275+
public mutating func insert(_ newElement: Element, at index: Int) {
276276
precondition(index >= 0 && index <= count,
277277
"Can't insert element at invalid index")
278278
_storage.ensureUnique(minimumCapacity: count + 1)
@@ -310,7 +310,7 @@ extension Deque: RangeReplaceableCollection {
310310
/// amortized O(1).
311311
@inlinable
312312
public mutating func insert<C: Collection>(
313-
contentsOf newElements: __owned C, at index: Index
313+
contentsOf newElements: __owned C, at index: Int
314314
) where C.Element == Element {
315315
precondition(index >= 0 && index <= count,
316316
"Can't insert elements at an invalid index")
@@ -338,7 +338,7 @@ extension Deque: RangeReplaceableCollection {
338338
/// deque costs O(1) if the deque's storage isn't shared.
339339
@inlinable
340340
@discardableResult
341-
public mutating func remove(at index: Index) -> Element {
341+
public mutating func remove(at index: Int) -> Element {
342342
precondition(index >= 0 && index < self.count, "Index out of bounds")
343343
// FIXME: Implement storage shrinking
344344
_storage.ensureUnique()
@@ -364,7 +364,7 @@ extension Deque: RangeReplaceableCollection {
364364
/// - Complexity: O(`count`). Removing elements from the start or end of the
365365
/// deque costs O(`bounds.count`) if the deque's storage isn't shared.
366366
@inlinable
367-
public mutating func removeSubrange(_ bounds: Range<Index>) {
367+
public mutating func removeSubrange(_ bounds: Range<Int>) {
368368
precondition(bounds.lowerBound >= 0 && bounds.upperBound <= self.count,
369369
"Index range out of bounds")
370370
_storage.ensureUnique()

Sources/DequeModule/Deque+Sequence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension Deque: Sequence {
4343
}
4444

4545
@inlinable
46-
internal init(_base: Deque, from index: Index) {
46+
internal init(_base: Deque, from index: Int) {
4747
assert(index <= _base.count)
4848
self = _base._storage.read { handle in
4949
let start = handle.slot(forOffset: index)

Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Elements.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ extension OrderedDictionary.Elements: RandomAccessCollection {
154154
/// - Complexity: O(1)
155155
@inlinable
156156
@inline(__always)
157-
public func index(after i: Index) -> Index { i + 1 }
157+
public func index(after i: Int) -> Int { i + 1 }
158158

159159
/// Returns the position immediately before the given index.
160160
///
@@ -168,7 +168,7 @@ extension OrderedDictionary.Elements: RandomAccessCollection {
168168
/// - Complexity: O(1)
169169
@inlinable
170170
@inline(__always)
171-
public func index(before i: Index) -> Index { i - 1 }
171+
public func index(before i: Int) -> Int { i - 1 }
172172

173173
/// Replaces the given index with its successor.
174174
///
@@ -180,7 +180,7 @@ extension OrderedDictionary.Elements: RandomAccessCollection {
180180
/// - Complexity: O(1)
181181
@inlinable
182182
@inline(__always)
183-
public func formIndex(after i: inout Index) { i += 1 }
183+
public func formIndex(after i: inout Int) { i += 1 }
184184

185185
/// Replaces the given index with its predecessor.
186186
///
@@ -192,7 +192,7 @@ extension OrderedDictionary.Elements: RandomAccessCollection {
192192
/// - Complexity: O(1)
193193
@inlinable
194194
@inline(__always)
195-
public func formIndex(before i: inout Index) { i -= 1 }
195+
public func formIndex(before i: inout Int) { i -= 1 }
196196

197197
/// Returns an index that is the specified distance from the given index.
198198
///
@@ -211,7 +211,7 @@ extension OrderedDictionary.Elements: RandomAccessCollection {
211211
/// - Complexity: O(1)
212212
@inlinable
213213
@inline(__always)
214-
public func index(_ i: Index, offsetBy distance: Int) -> Index {
214+
public func index(_ i: Int, offsetBy distance: Int) -> Int {
215215
i + distance
216216
}
217217

@@ -238,10 +238,10 @@ extension OrderedDictionary.Elements: RandomAccessCollection {
238238
@inlinable
239239
@inline(__always)
240240
public func index(
241-
_ i: Index,
241+
_ i: Int,
242242
offsetBy distance: Int,
243-
limitedBy limit: Index
244-
) -> Index? {
243+
limitedBy limit: Int
244+
) -> Int? {
245245
_base._values.index(i, offsetBy: distance, limitedBy: limit)
246246
}
247247

@@ -257,7 +257,7 @@ extension OrderedDictionary.Elements: RandomAccessCollection {
257257
/// - Complexity: O(1)
258258
@inlinable
259259
@inline(__always)
260-
public func distance(from start: Index, to end: Index) -> Int {
260+
public func distance(from start: Int, to end: Int) -> Int {
261261
end - start
262262
}
263263

@@ -270,7 +270,7 @@ extension OrderedDictionary.Elements: RandomAccessCollection {
270270
/// - Complexity: O(1)
271271
@inlinable
272272
@inline(__always)
273-
public subscript(position: Index) -> Element {
273+
public subscript(position: Int) -> Element {
274274
(_base._keys[position], _base._values[position])
275275
}
276276

@@ -313,13 +313,13 @@ extension OrderedDictionary.Elements: RandomAccessCollection {
313313

314314
@inlinable
315315
@inline(__always)
316-
public func _failEarlyRangeCheck(_ index: Index, bounds: ClosedRange<Index>) {
316+
public func _failEarlyRangeCheck(_ index: Int, bounds: ClosedRange<Int>) {
317317
_base._values._failEarlyRangeCheck(index, bounds: bounds)
318318
}
319319

320320
@inlinable
321321
@inline(__always)
322-
public func _failEarlyRangeCheck(_ range: Range<Index>, bounds: Range<Index>) {
322+
public func _failEarlyRangeCheck(_ range: Range<Int>, bounds: Range<Int>) {
323323
_base._values._failEarlyRangeCheck(range, bounds: bounds)
324324
}
325325
}
@@ -373,7 +373,7 @@ extension OrderedDictionary.Elements {
373373
/// value; O(`count`) otherwise.
374374
@inlinable
375375
@inline(__always)
376-
public mutating func swapAt(_ i: Index, _ j: Index) {
376+
public mutating func swapAt(_ i: Int, _ j: Int) {
377377
_base.swapAt(i, j)
378378
}
379379

@@ -398,7 +398,7 @@ extension OrderedDictionary.Elements {
398398
@inline(__always)
399399
public mutating func partition(
400400
by belongsInSecondPartition: (Element) throws -> Bool
401-
) rethrows -> Index {
401+
) rethrows -> Int {
402402
try _base.partition(by: belongsInSecondPartition)
403403
}
404404
}

Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Partial MutableCollection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension OrderedDictionary {
2222
/// - Complexity: O(1) when the dictionary's storage isn't shared with another
2323
/// value; O(`count`) otherwise.
2424
@inlinable
25-
public mutating func swapAt(_ i: Index, _ j: Index) {
25+
public mutating func swapAt(_ i: Int, _ j: Int) {
2626
_keys.swapAt(i, j)
2727
_values.swapAt(i, j)
2828
}
@@ -47,7 +47,7 @@ extension OrderedDictionary {
4747
@inlinable
4848
public mutating func partition(
4949
by belongsInSecondPartition: (Element) throws -> Bool
50-
) rethrows -> Index {
50+
) rethrows -> Int {
5151
let pivot = try _values.withUnsafeMutableBufferPointer { values in
5252
try _keys._partition(values: values, by: belongsInSecondPartition)
5353
}

Sources/OrderedCollections/OrderedDictionary/OrderedDictionary+Values.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ extension OrderedDictionary.Values: RandomAccessCollection {
143143
/// - Complexity: O(1)
144144
@inlinable
145145
@inline(__always)
146-
public func index(after i: Index) -> Index { i + 1 }
146+
public func index(after i: Int) -> Int { i + 1 }
147147

148148
/// Returns the position immediately before the given index.
149149
///
@@ -157,7 +157,7 @@ extension OrderedDictionary.Values: RandomAccessCollection {
157157
/// - Complexity: O(1)
158158
@inlinable
159159
@inline(__always)
160-
public func index(before i: Index) -> Index { i - 1 }
160+
public func index(before i: Int) -> Int { i - 1 }
161161

162162
/// Replaces the given index with its successor.
163163
///
@@ -169,7 +169,7 @@ extension OrderedDictionary.Values: RandomAccessCollection {
169169
/// - Complexity: O(1)
170170
@inlinable
171171
@inline(__always)
172-
public func formIndex(after i: inout Index) { i += 1 }
172+
public func formIndex(after i: inout Int) { i += 1 }
173173

174174
/// Replaces the given index with its predecessor.
175175
///
@@ -181,7 +181,7 @@ extension OrderedDictionary.Values: RandomAccessCollection {
181181
/// - Complexity: O(1)
182182
@inlinable
183183
@inline(__always)
184-
public func formIndex(before i: inout Index) { i -= 1 }
184+
public func formIndex(before i: inout Int) { i -= 1 }
185185

186186
/// Returns an index that is the specified distance from the given index.
187187
///
@@ -200,7 +200,7 @@ extension OrderedDictionary.Values: RandomAccessCollection {
200200
/// - Complexity: O(1)
201201
@inlinable
202202
@inline(__always)
203-
public func index(_ i: Index, offsetBy distance: Int) -> Index {
203+
public func index(_ i: Int, offsetBy distance: Int) -> Int {
204204
i + distance
205205
}
206206

@@ -227,10 +227,10 @@ extension OrderedDictionary.Values: RandomAccessCollection {
227227
@inlinable
228228
@inline(__always)
229229
public func index(
230-
_ i: Index,
230+
_ i: Int,
231231
offsetBy distance: Int,
232-
limitedBy limit: Index
233-
) -> Index? {
232+
limitedBy limit: Int
233+
) -> Int? {
234234
_base._values.index(i, offsetBy: distance, limitedBy: limit)
235235
}
236236

@@ -246,7 +246,7 @@ extension OrderedDictionary.Values: RandomAccessCollection {
246246
/// - Complexity: O(1)
247247
@inlinable
248248
@inline(__always)
249-
public func distance(from start: Index, to end: Index) -> Int {
249+
public func distance(from start: Int, to end: Int) -> Int {
250250
end - start
251251
}
252252

@@ -279,7 +279,7 @@ extension OrderedDictionary.Values: MutableCollection {
279279
/// - Complexity: O(1)
280280
@inlinable
281281
@inline(__always)
282-
public subscript(position: Index) -> Value {
282+
public subscript(position: Int) -> Value {
283283
get {
284284
_base._values[position]
285285
}

0 commit comments

Comments
 (0)