Skip to content

Commit 9bcd5a1

Browse files
committed
Collection.length => .count
1 parent 29b26cf commit 9bcd5a1

File tree

183 files changed

+2028
-2025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+2028
-2025
lines changed

docs/Generics.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ requirements. Protocols can also contain operators, properties, and subscript
261261
operators::
262262
263263
protocol RandomAccessContainer : Collection {
264-
var length : Int
265-
func ==(lhs : Self, rhs : Self)
266-
subscript (i : Int) -> Element
264+
var count: Int
265+
func == (lhs: Self, rhs: Self)
266+
subscript(i: Int) -> Element
267267
}
268268

269269
Operator requirements can be satisfied by operator definitions, property

docs/HighLevelSILOptimizations.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ array.check_subscript(index: Int)
195195
read. No state is written. Despite being read only, this operation is control
196196
dependent.
197197

198-
array.get_length() -> Int
198+
array.get_count() -> Int
199199

200200
Read the array count (``array.endIndex - array.startIndex``) from the storage
201201
descriptor. No elements are read. No state is written. This is neither guarded
@@ -204,7 +204,7 @@ array.get_length() -> Int
204204
array.get_capacity() -> Int
205205

206206
Read the array capacity from the storage descriptor. The semantics
207-
are identical to ``get_length`` except for the meaning of the return value.
207+
are identical to ``get_count`` except for the meaning of the return value.
208208

209209
array.make_mutable()
210210

@@ -263,7 +263,7 @@ check_subscript guards get_element, get_element_address
263263
make_mutable interferes-with props.isCocoa/needsElementTypeCheck
264264
get_elt_addr interferes-with get_element, get_element_address,
265265
props.isCocoa/needsElementTypeCheck
266-
mutate_unknown interferes-with get_element, check_subscript, get_length,
266+
mutate_unknown interferes-with get_element, check_subscript, get_count,
267267
get_capacity, get_element_address,
268268
props.isCocoa/needsElementTypeCheck
269269
================ =============== ==========================================

lib/SILOptimizer/Analysis/ArraySemantic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ ArrayCallKind swift::ArraySemanticsCall::getKind() const {
147147
.Case("array.uninitialized", ArrayCallKind::kArrayUninitialized)
148148
.Case("array.check_subscript", ArrayCallKind::kCheckSubscript)
149149
.Case("array.check_index", ArrayCallKind::kCheckIndex)
150-
.Case("array.get_length", ArrayCallKind::kGetCount)
150+
.Case("array.get_count", ArrayCallKind::kGetCount)
151151
.Case("array.get_capacity", ArrayCallKind::kGetCapacity)
152152
.Case("array.get_element", ArrayCallKind::kGetElement)
153153
.Case("array.owner", ArrayCallKind::kGetArrayOwner)

stdlib/private/StdlibUnittest/CheckCollection.swift

+18-19
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public struct SubscriptRangeTest {
1414
public let expected: [OpaqueValue<Int>]
1515
public let collection: [OpaqueValue<Int>]
1616
public let bounds: Range<Int>
17-
public let length: Int
17+
public let count: Int
1818
public let loc: SourceLoc
1919

20-
public var isEmpty: Bool { return length == 0 }
20+
public var isEmpty: Bool { return count == 0 }
2121

2222
public func boundsIn<C : Collection>(c: C) -> Range<C.Index> {
2323
let i = c.startIndex
@@ -28,14 +28,13 @@ public struct SubscriptRangeTest {
2828

2929
public init(
3030
expected: [Int], collection: [Int], bounds: Range<Int>,
31-
length: Int,
31+
count: Int,
3232
file: String = __FILE__, line: UInt = __LINE__
3333
) {
34-
require(length == collection.length)
3534
self.expected = expected.map(OpaqueValue.init)
3635
self.collection = collection.map(OpaqueValue.init)
3736
self.bounds = bounds
38-
self.length = length
37+
self.count = count
3938
self.loc = SourceLoc(file, line, comment: "test data")
4039
}
4140
}
@@ -114,66 +113,66 @@ public let subscriptRangeTests = [
114113
expected: [],
115114
collection: [],
116115
bounds: 0..<0,
117-
length: 0),
116+
count: 0),
118117

119118
// Slice to the full extent.
120119
SubscriptRangeTest(
121120
expected: [ 1010 ],
122121
collection: [ 1010 ],
123122
bounds: 0..<1,
124-
length: 1),
123+
count: 1),
125124
SubscriptRangeTest(
126125
expected: [ 1010, 2020, 3030 ],
127126
collection: [ 1010, 2020, 3030 ],
128127
bounds: 0..<3,
129-
length: 3),
128+
count: 3),
130129

131130
// Slice an empty prefix.
132131
SubscriptRangeTest(
133132
expected: [],
134133
collection: [ 1010, 2020, 3030 ],
135134
bounds: 0..<0,
136-
length: 3),
135+
count: 3),
137136

138137
// Slice a prefix.
139138
SubscriptRangeTest(
140139
expected: [ 1010, 2020 ],
141140
collection: [ 1010, 2020, 3030 ],
142141
bounds: 0..<2,
143-
length: 3),
142+
count: 3),
144143

145144
// Slice an empty suffix.
146145
SubscriptRangeTest(
147146
expected: [],
148147
collection: [ 1010, 2020, 3030 ],
149148
bounds: 3..<3,
150-
length: 3),
149+
count: 3),
151150

152151
// Slice a suffix.
153152
SubscriptRangeTest(
154153
expected: [ 2020, 3030 ],
155154
collection: [ 1010, 2020, 3030 ],
156155
bounds: 1..<3,
157-
length: 3),
156+
count: 3),
158157

159158
// Slice an empty range in the middle.
160159
SubscriptRangeTest(
161160
expected: [],
162161
collection: [ 1010, 2020, 3030 ],
163162
bounds: 2..<2,
164-
length: 3),
163+
count: 3),
165164

166165
// Slice the middle part.
167166
SubscriptRangeTest(
168167
expected: [ 2020 ],
169168
collection: [ 1010, 2020, 3030 ],
170169
bounds: 1..<2,
171-
length: 3),
170+
count: 3),
172171
SubscriptRangeTest(
173172
expected: [ 2020, 3030, 4040 ],
174173
collection: [ 1010, 2020, 3030, 4040, 5050, 6060 ],
175174
bounds: 1..<4,
176-
length: 6),
175+
count: 6),
177176
]
178177

179178
public let prefixUpToTests = [
@@ -482,13 +481,13 @@ self.test("\(testNamePrefix).isEmpty/semantics") {
482481
}
483482

484483
//===----------------------------------------------------------------------===//
485-
// length
484+
// count
486485
//===----------------------------------------------------------------------===//
487486

488-
self.test("\(testNamePrefix).length/semantics") {
487+
self.test("\(testNamePrefix).count/semantics") {
489488
for test in subscriptRangeTests {
490489
let c = makeWrappedCollection(test.collection)
491-
expectEqual(test.length, numericCast(c.length) as Int)
490+
expectEqual(test.count, numericCast(c.count) as Int)
492491
}
493492
}
494493

@@ -842,7 +841,7 @@ self.test("\(testNamePrefix).last") {
842841
expectEmpty(result)
843842
} else {
844843
expectOptionalEqual(
845-
test.collection[test.length - 1],
844+
test.collection[test.count - 1],
846845
result.map(extractValue)
847846
) { $0.value == $1.value }
848847
}

stdlib/private/StdlibUnittest/CheckMutableCollection.swift.gyb

+15-15
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ self.test("\(testNamePrefix)._withUnsafeMutableBufferPointerIfSupported()/semant
222222
for test in subscriptRangeTests {
223223
var c = makeWrappedCollection(test.collection)
224224
var result = c._withUnsafeMutableBufferPointerIfSupported {
225-
(baseAddress, length) -> OpaqueValue<Array<OpaqueValue<Int>>> in
225+
(baseAddress, count) -> OpaqueValue<Array<OpaqueValue<Int>>> in
226226
let bufferPointer =
227-
UnsafeMutableBufferPointer(start: baseAddress, length: length)
227+
UnsafeMutableBufferPointer(start: baseAddress, count: count)
228228
return OpaqueValue(Array(bufferPointer.map(extractValue)))
229229
}
230230
expectType(Optional<OpaqueValue<Array<OpaqueValue<Int>>>>.self, &result)
@@ -246,13 +246,13 @@ self.test("\(testNamePrefix).sorted/DispatchesThrough_withUnsafeMutableBufferPoi
246246
let sequence = [ 5, 4, 3, 2, 1 ]
247247
% if predicate:
248248
let elements: [OpaqueValue<Int>] =
249-
zip(sequence, 0..<sequence.length).map {
249+
zip(sequence, 0..<sequence.count).map {
250250
OpaqueValue($0, identity: $1)
251251
}
252252
let c = makeWrappedCollection(elements)
253253
% else:
254254
let elements: [MinimalComparableValue] =
255-
zip(sequence, 0..<sequence.length).map {
255+
zip(sequence, 0..<sequence.count).map {
256256
MinimalComparableValue($0, identity: $1)
257257
}
258258
let c = makeWrappedCollectionWithComparableElement(elements)
@@ -288,7 +288,7 @@ func checkSort_${'Predicate' if predicate else 'WhereElementIsComparable'}(
288288
% if predicate:
289289
let extract = extractValue
290290
let elements: [OpaqueValue<Int>] =
291-
zip(sequence, 0..<sequence.length).map {
291+
zip(sequence, 0..<sequence.count).map {
292292
OpaqueValue($0, identity: $1)
293293
}
294294
let c = makeWrappedCollection(elements)
@@ -304,7 +304,7 @@ func checkSort_${'Predicate' if predicate else 'WhereElementIsComparable'}(
304304

305305
let extract = extractValueFromComparable
306306
let elements: [MinimalComparableValue] =
307-
zip(sequence, 0..<sequence.length).map {
307+
zip(sequence, 0..<sequence.count).map {
308308
MinimalComparableValue($0, identity: $1)
309309
}
310310
let c = makeWrappedCollectionWithComparableElement(elements)
@@ -320,7 +320,7 @@ func checkSort_${'Predicate' if predicate else 'WhereElementIsComparable'}(
320320

321321
// Check that we didn't lose any elements.
322322
expectEqualsUnordered(
323-
0..<sequence.length,
323+
0..<sequence.count,
324324
extractedResult.map { $0.identity })
325325

326326
// Check that the elements are sorted.
@@ -589,7 +589,7 @@ func checkSortInPlace_${'Predicate' if predicate else 'WhereElementIsComparable'
589589
% if predicate:
590590
let extract = extractValue
591591
let elements: [OpaqueValue<Int>] =
592-
zip(sequence, 0..<sequence.length).map {
592+
zip(sequence, 0..<sequence.count).map {
593593
OpaqueValue($0, identity: $1)
594594
}
595595

@@ -606,7 +606,7 @@ func checkSortInPlace_${'Predicate' if predicate else 'WhereElementIsComparable'
606606

607607
let extract = extractValueFromComparable
608608
let elements: [MinimalComparableValue] =
609-
zip(sequence, 0..<sequence.length).map {
609+
zip(sequence, 0..<sequence.count).map {
610610
MinimalComparableValue($0, identity: $1)
611611
}
612612

@@ -618,7 +618,7 @@ func checkSortInPlace_${'Predicate' if predicate else 'WhereElementIsComparable'
618618

619619
// Check that we didn't lose any elements.
620620
expectEqualsUnordered(
621-
0..<sequence.length,
621+
0..<sequence.count,
622622
extractedResult.map { $0.identity })
623623

624624
// Check that the elements are sorted.
@@ -679,7 +679,7 @@ func checkPartition_${'Predicate' if predicate else 'WhereElementIsComparable'}(
679679
% if predicate:
680680
let extract = extractValue
681681
let elements: [OpaqueValue<Int>] =
682-
zip(sequence, 0..<sequence.length).map {
682+
zip(sequence, 0..<sequence.count).map {
683683
OpaqueValue($0, identity: $1)
684684
}
685685

@@ -690,7 +690,7 @@ func checkPartition_${'Predicate' if predicate else 'WhereElementIsComparable'}(
690690

691691
let extract = extractValueFromComparable
692692
let elements: [MinimalComparableValue] =
693-
zip(sequence, 0..<sequence.length).map {
693+
zip(sequence, 0..<sequence.count).map {
694694
MinimalComparableValue($0, identity: $1)
695695
}
696696

@@ -710,7 +710,7 @@ func checkPartition_${'Predicate' if predicate else 'WhereElementIsComparable'}(
710710

711711
// Check that we didn't lose any elements.
712712
let identities = c.map { extract($0).identity }
713-
expectEqualsUnordered(0..<sequence.length, identities)
713+
expectEqualsUnordered(0..<sequence.count, identities)
714714

715715
if verifyOrder {
716716
// All the elements in the first partition are less than the pivot
@@ -760,14 +760,14 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer
760760
% if predicate:
761761
let extract = extractValue
762762
let elements: [OpaqueValue<Int>] =
763-
zip(sequence, 0..<sequence.length).map {
763+
zip(sequence, 0..<sequence.count).map {
764764
OpaqueValue($0, identity: $1)
765765
}
766766
let c = makeWrappedCollection(elements)
767767
% else:
768768
let extract = extractValueFromComparable
769769
let elements: [MinimalComparableValue] =
770-
zip(sequence, 0..<sequence.length).map {
770+
zip(sequence, 0..<sequence.count).map {
771771
MinimalComparableValue($0, identity: $1)
772772
}
773773
let c = makeWrappedCollectionWithComparableElement(elements)

stdlib/private/StdlibUnittest/CheckRangeReplaceableCollection.swift

+12-11
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ internal enum RangeSelection {
2626
case .LeftEdge: return collection.startIndex..<collection.startIndex
2727
case .RightEdge: return collection.endIndex..<collection.endIndex
2828
case .Middle:
29-
let start = collection.startIndex.advancedBy(collection.length / 4)
30-
let end = collection.startIndex.advancedBy(3 * collection.length / 4)
29+
let start = collection.startIndex.advancedBy(collection.count / 4)
30+
let end = collection.startIndex.advancedBy(3 * collection.count / 4)
3131
return start...end
3232
case .LeftHalf:
3333
let start = collection.startIndex
34-
let end = start.advancedBy(collection.length / 2)
34+
let end = start.advancedBy(collection.count / 2)
3535
return start..<end
3636
case .RightHalf:
37-
let start = collection.startIndex.advancedBy(collection.length / 2)
37+
let start = collection.startIndex.advancedBy(collection.count / 2)
3838
let end = collection.endIndex
3939
return start..<end
4040
}
@@ -50,9 +50,9 @@ internal enum IndexSelection {
5050
internal func indexIn<C : Collection>(collection: C) -> C.Index {
5151
switch self {
5252
case .Start: return collection.startIndex
53-
case .Middle: return collection.startIndex.advancedBy(collection.length / 2)
53+
case .Middle: return collection.startIndex.advancedBy(collection.count / 2)
5454
case .End: return collection.endIndex
55-
case .Last: return collection.startIndex.advancedBy(collection.length - 1)
55+
case .Last: return collection.startIndex.advancedBy(collection.count - 1)
5656
}
5757
}
5858
}
@@ -411,20 +411,21 @@ self.test("\(testNamePrefix).init(Sequence)/semantics") {
411411
}
412412

413413
//===----------------------------------------------------------------------===//
414-
// init(repeating:length:)
414+
// init(repeating:count:)
415415
//===----------------------------------------------------------------------===//
416416

417-
self.test("\(testNamePrefix).init(repeating:length:)/semantics") {
418-
let c = C(repeating: wrapValue(OpaqueValue(42)), length: 3)
417+
self.test("\(testNamePrefix).init(repeating:count:)/semantics") {
418+
let c = C(repeating: wrapValue(OpaqueValue(42)), count: 3)
419419
expectEqualSequence(
420420
[42, 42, 42],
421421
c.map { extractValue($0).value })
422-
let empty = C(repeating: wrapValue(OpaqueValue(42)), length: 0)
422+
let empty = C(repeating: wrapValue(OpaqueValue(42)), count: 0)
423423
expectEqualSequence(
424424
[],
425425
empty.map { extractValue($0).value })
426+
426427
expectCrashLater()
427-
C(repeating: wrapValue(OpaqueValue(42)), length: -1)
428+
_ = C(repeating: wrapValue(OpaqueValue(42)), count: -1)
428429
}
429430

430431
//===----------------------------------------------------------------------===//

stdlib/private/StdlibUnittest/CheckSequenceType.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1425,8 +1425,8 @@ public let zipTests = [
14251425
leftovers: [], []),
14261426
]
14271427

1428-
public func callGenericUnderestimatedLength<S : Sequence>(s: S) -> Int {
1429-
return s.underestimatedLength
1428+
public func callGenericUnderestimatedCount<S : Sequence>(s: S) -> Int {
1429+
return s.underestimatedCount
14301430
}
14311431

14321432
extension TestSuite {

0 commit comments

Comments
 (0)