Skip to content

Commit 8ac6c7c

Browse files
committed
Remove {Dictionary,Set,UnsafeMutableBufferPointer,UnsafeBufferPointer}.count
These APIs are redundant with APIs that come from protocol extensions. Swift SVN r28248
1 parent 58601fa commit 8ac6c7c

21 files changed

+315
-316
lines changed

stdlib/private/SwiftPrivate/IO.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public struct _FDOutputStream : OutputStreamType {
104104
utf8.withUnsafeBufferPointer {
105105
(utf8) -> () in
106106
var writtenBytes = 0
107-
let bufferSize = utf8.count - 1
107+
let bufferSize = utf8.count() - 1
108108
while writtenBytes != bufferSize {
109109
let result = SwiftShims.write(
110110
self.fd, UnsafePointer(utf8.baseAddress + Int(writtenBytes)),

stdlib/private/SwiftPrivateDarwinExtras/Subprocess.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ internal func _readAll(fd: CInt) -> String {
117117
let readResult: ssize_t = buffer.withUnsafeMutableBufferPointer {
118118
(buffer) in
119119
let ptr = UnsafeMutablePointer<Void>(buffer.baseAddress + usedBytes)
120-
return read(fd, ptr, size_t(buffer.count - usedBytes))
120+
return read(fd, ptr, size_t(buffer.count() - usedBytes))
121121
}
122122
if readResult > 0 {
123123
usedBytes += readResult

stdlib/public/SDK/CoreAudio/CoreAudio.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension AudioBuffer {
3636
_ typedBuffer: UnsafeMutableBufferPointer<T>, numberOfChannels: Int) {
3737
self.mNumberChannels = UInt32(numberOfChannels)
3838
self.mData = UnsafeMutablePointer<Void>(typedBuffer.baseAddress)
39-
self.mDataByteSize = UInt32(typedBuffer.count * strideof(T))
39+
self.mDataByteSize = UInt32(typedBuffer.count() * strideof(T))
4040
}
4141
}
4242

stdlib/public/core/AssertCommon.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ func _assertionFailed(
9797
file.withUTF8Buffer {
9898
(file) -> () in
9999
_reportFatalErrorInFile(
100-
prefix.baseAddress, UWord(prefix.count),
101-
message.baseAddress, UWord(message.count),
102-
file.baseAddress, UWord(file.count), line)
100+
prefix.baseAddress, UWord(prefix.count()),
101+
message.baseAddress, UWord(message.count()),
102+
file.baseAddress, UWord(file.count()), line)
103103
Builtin.int_trap()
104104
}
105105
}
@@ -125,9 +125,9 @@ func _assertionFailed(
125125
file.withUTF8Buffer {
126126
(file) -> () in
127127
_reportFatalErrorInFile(
128-
prefix.baseAddress, UWord(prefix.count),
129-
messageUTF8.baseAddress, UWord(messageUTF8.count),
130-
file.baseAddress, UWord(file.count), line)
128+
prefix.baseAddress, UWord(prefix.count()),
129+
messageUTF8.baseAddress, UWord(messageUTF8.count()),
130+
file.baseAddress, UWord(file.count()), line)
131131
}
132132
}
133133
}
@@ -152,9 +152,9 @@ func _fatalErrorMessage(prefix: StaticString, _ message: StaticString,
152152
file.withUTF8Buffer {
153153
(file) in
154154
_reportFatalErrorInFile(
155-
prefix.baseAddress, UWord(prefix.count),
156-
message.baseAddress, UWord(message.count),
157-
file.baseAddress, UWord(file.count), line)
155+
prefix.baseAddress, UWord(prefix.count()),
156+
message.baseAddress, UWord(message.count()),
157+
file.baseAddress, UWord(file.count()), line)
158158
}
159159
}
160160
}
@@ -195,9 +195,9 @@ func _unimplemented_initializer(className: StaticString,
195195
file.withUTF8Buffer {
196196
(file) in
197197
_reportUnimplementedInitializerInFile(
198-
className.baseAddress, UWord(className.count),
199-
initName.baseAddress, UWord(initName.count),
200-
file.baseAddress, UWord(file.count), line, column)
198+
className.baseAddress, UWord(className.count()),
199+
initName.baseAddress, UWord(initName.count()),
200+
file.baseAddress, UWord(file.count()), line, column)
201201
}
202202
}
203203
}
@@ -207,8 +207,8 @@ func _unimplemented_initializer(className: StaticString,
207207
initName.withUTF8Buffer {
208208
(initName) in
209209
_reportUnimplementedInitializer(
210-
className.baseAddress, UWord(className.count),
211-
initName.baseAddress, UWord(initName.count))
210+
className.baseAddress, UWord(className.count()),
211+
initName.baseAddress, UWord(initName.count()))
212212
}
213213
}
214214
}

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,12 @@ public struct Set<T : Hashable> :
394394

395395
/// Remove a member from the set and return it. Requires: `count > 0`.
396396
public mutating func removeFirst() -> T {
397-
_precondition(count > 0, "can't removeFirst from an empty Set")
397+
_precondition(!isEmpty, "can't removeFirst from an empty Set")
398398
let member = first!
399399
remove(member)
400400
return member
401401
}
402402

403-
/// The number of members in the set.
404-
///
405-
/// - complexity: O(1)
406-
public var count: Int {
407-
return _variantStorage.count
408-
}
409-
410403
//
411404
// `SequenceType` conformance
412405
//
@@ -470,7 +463,7 @@ public struct Set<T : Hashable> :
470463
/// The first element obtained when iterating, or `nil` if `self` is
471464
/// empty. Equivalent to `self.generate().next()`
472465
public var first: T? {
473-
return count > 0 ? self[startIndex] : .None
466+
return !isEmpty ? self[startIndex] : .None
474467
}
475468

476469
/// Returns true if the set is a subset of a finite sequence as a `Set`.
@@ -588,7 +581,7 @@ public struct Set<T : Hashable> :
588581
// The result can only have fewer or the same number of elements.
589582
// If no elements were removed, don't perform a reassignment
590583
// as this may cause an unnecessary uniquing COW.
591-
if result.count != count {
584+
if result.count() != count() {
592585
self = result
593586
}
594587
}
@@ -646,7 +639,14 @@ public struct Set<T : Hashable> :
646639

647640
/// `true` if the set is empty.
648641
public var isEmpty: Bool {
649-
return count == 0
642+
return count() == 0
643+
}
644+
645+
/// The number of members in the set.
646+
///
647+
/// - complexity: O(1)
648+
public func count() -> Int {
649+
return _variantStorage.count
650650
}
651651
}
652652

@@ -661,7 +661,7 @@ internal func _compareSets<T>(lhs: Set<T>, _ rhs: Set<T>)
661661
return (false, false)
662662
}
663663
}
664-
return (true, lhs.count == rhs.count)
664+
return (true, lhs.count() == rhs.count())
665665
}
666666

667667
public func == <T : Hashable>(lhs: Set<T>, rhs: Set<T>) -> Bool {
@@ -785,7 +785,7 @@ public func _setUpCast<DerivedValue, BaseValue>(source: Set<DerivedValue>)
785785
_sanityCheck(_isClassOrObjCExistential(BaseValue.self))
786786
_sanityCheck(_isClassOrObjCExistential(DerivedValue.self))
787787

788-
var builder = _SetBuilder<BaseValue>(count: source.count)
788+
var builder = _SetBuilder<BaseValue>(count: source.count())
789789
for member in source {
790790
builder.add(member: unsafeBitCast(member, BaseValue.self))
791791
}
@@ -804,7 +804,7 @@ public func _setBridgeToObjectiveC<SwiftValue, ObjCValue>(
804804
_sanityCheck(_isClassOrObjCExistential(ObjCValue.self))
805805
_sanityCheck(!_isBridgedVerbatimToObjectiveC(SwiftValue.self))
806806

807-
var result = Set<ObjCValue>(minimumCapacity: source.count)
807+
var result = Set<ObjCValue>(minimumCapacity: source.count())
808808
let valueBridgesDirectly =
809809
_isBridgedVerbatimToObjectiveC(SwiftValue.self) ==
810810
_isBridgedVerbatimToObjectiveC(ObjCValue.self)
@@ -862,7 +862,7 @@ public func _setDownCastConditional<BaseValue, DerivedValue>(
862862
_sanityCheck(_isClassOrObjCExistential(BaseValue.self))
863863
_sanityCheck(_isClassOrObjCExistential(DerivedValue.self))
864864

865-
var result = Set<DerivedValue>(minimumCapacity: source.count)
865+
var result = Set<DerivedValue>(minimumCapacity: source.count())
866866
for member in source {
867867
if let derivedMember = member as? DerivedValue {
868868
result.insert(derivedMember)
@@ -904,7 +904,7 @@ public func _setBridgeFromObjectiveCConditional<
904904
_isBridgedVerbatimToObjectiveC(SwiftValue.self) ==
905905
_isBridgedVerbatimToObjectiveC(ObjCValue.self)
906906

907-
var result = Set<SwiftValue>(minimumCapacity: source.count)
907+
var result = Set<SwiftValue>(minimumCapacity: source.count())
908908
for value in source {
909909
// Downcast the value.
910910
var resultValue: SwiftValue
@@ -1114,13 +1114,6 @@ public struct Dictionary<Key : Hashable, Value> :
11141114
_variantStorage.removeAll(keepCapacity: keepCapacity)
11151115
}
11161116

1117-
/// The number of entries in the dictionary.
1118-
///
1119-
/// - complexity: O(1)
1120-
public var count: Int {
1121-
return _variantStorage.count
1122-
}
1123-
11241117
//
11251118
// `SequenceType` conformance
11261119
//
@@ -1177,9 +1170,15 @@ public struct Dictionary<Key : Hashable, Value> :
11771170

11781171
/// True iff `count == 0`
11791172
public var isEmpty: Bool {
1180-
return count == 0
1173+
return count() == 0
11811174
}
11821175

1176+
/// The number of entries in the dictionary.
1177+
///
1178+
/// - complexity: O(1)
1179+
public func count() -> Int {
1180+
return _variantStorage.count
1181+
}
11831182
}
11841183

11851184
public func == <Key : Equatable, Value : Equatable>(
@@ -1266,7 +1265,7 @@ public func != <Key : Equatable, Value : Equatable>(
12661265

12671266
extension Dictionary : CustomStringConvertible, CustomDebugStringConvertible {
12681267
internal func _makeDescription(isDebug isDebug: Bool) -> String {
1269-
if count == 0 {
1268+
if isEmpty {
12701269
return "[:]"
12711270
}
12721271

@@ -1338,7 +1337,7 @@ public func _dictionaryUpCast<DerivedKey, DerivedValue, BaseKey, BaseValue>(
13381337
_sanityCheck(_isClassOrObjCExistential(DerivedKey.self))
13391338
_sanityCheck(_isClassOrObjCExistential(DerivedValue.self))
13401339

1341-
var result = Dictionary<BaseKey, BaseValue>(minimumCapacity: source.count)
1340+
var result = Dictionary<BaseKey, BaseValue>(minimumCapacity: source.count())
13421341
for (k, v) in source {
13431342
result[unsafeBitCast(k, BaseKey.self)] = unsafeBitCast(v, BaseValue.self)
13441343
}
@@ -1363,7 +1362,7 @@ public func _dictionaryBridgeToObjectiveC<
13631362
_isClassOrObjCExistential(ObjCKey.self) ||
13641363
_isClassOrObjCExistential(ObjCValue.self))
13651364

1366-
var result = Dictionary<ObjCKey, ObjCValue>(minimumCapacity: source.count)
1365+
var result = Dictionary<ObjCKey, ObjCValue>(minimumCapacity: source.count())
13671366
let keyBridgesDirectly =
13681367
_isBridgedVerbatimToObjectiveC(SwiftKey.self) ==
13691368
_isBridgedVerbatimToObjectiveC(ObjCKey.self)
@@ -3726,7 +3725,7 @@ internal class ${Self}Mirror<${TypeParametersDecl}> : MirrorType {
37263725

37273726
internal var objectIdentifier: ObjectIdentifier? { return nil }
37283727

3729-
internal var count: Int { return _mirror.count }
3728+
internal var count: Int { return _mirror.count() }
37303729

37313730
internal subscript(i: Int) -> (String, MirrorType) {
37323731
_precondition(i >= 0 && i < count, "MirrorType access out of bounds")

stdlib/public/core/Reflection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func _dumpWithMirror<TargetStream : OutputStreamType>(
276276
println(" #\(previous)", &targetStream)
277277
return
278278
}
279-
let identifier = visitedItems.count
279+
let identifier = visitedItems.count()
280280
visitedItems[id] = identifier
281281
print(" #\(identifier)", &targetStream)
282282
}

stdlib/public/core/Repeat.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct Repeat<T> : CollectionType {
2222
/// Construct an instance that contains `count` elements having the
2323
/// value `repeatedValue`.
2424
public init(count: Int, repeatedValue: T) {
25-
self.count = count
25+
self._count = count
2626
self.repeatedValue = repeatedValue
2727
}
2828

@@ -32,10 +32,10 @@ public struct Repeat<T> : CollectionType {
3232
return 0
3333
}
3434

35-
/// Always equal to `count`, which is one greater than the index of
35+
/// Always equal to `count()`, which is one greater than the index of
3636
/// the last element in a non-empty instance.
3737
public var endIndex: Index {
38-
return count
38+
return _count
3939
}
4040

4141
/// Return a *generator* over the elements of this *sequence*.
@@ -50,12 +50,12 @@ public struct Repeat<T> : CollectionType {
5050
/// Requires: `position` is a valid position in `self` and
5151
/// `position != endIndex`.
5252
public subscript(position: Int) -> T {
53-
_precondition(position >= 0 && position < count, "Index out of range")
53+
_precondition(position >= 0 && position < _count, "Index out of range")
5454
return repeatedValue
5555
}
5656

5757
/// The number of elements in this collection.
58-
public var count: Int
58+
internal var _count: Int
5959

6060
/// The value of every element in this collection.
6161
public let repeatedValue: T

stdlib/public/core/SwiftNativeNSArray.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ class _SwiftNativeNSArrayWithContiguousStorage
5252
// Implement the APIs required by NSArray
5353
extension _SwiftNativeNSArrayWithContiguousStorage: _NSArrayCoreType {
5454
@objc internal var count: Int {
55-
return withUnsafeBufferOfObjects { $0.count }
55+
return withUnsafeBufferOfObjects { $0.count() }
5656
}
5757

5858
@objc internal final func objectAtIndex(index: Int) -> AnyObject {
5959
return withUnsafeBufferOfObjects {
6060
objects in
6161
_precondition(
62-
_isValidArraySubscript(index, objects.count),
62+
_isValidArraySubscript(index, objects.count()),
6363
"Array index out of range")
6464
return objects[index]
6565
}
@@ -71,12 +71,12 @@ extension _SwiftNativeNSArrayWithContiguousStorage: _NSArrayCoreType {
7171
return withUnsafeBufferOfObjects {
7272
objects in
7373
_precondition(
74-
_isValidArrayIndex(range.location, objects.count),
74+
_isValidArrayIndex(range.location, objects.count()),
7575
"Array index out of range")
7676

7777
_precondition(
7878
_isValidArrayIndex(
79-
range.location + range.length, objects.count),
79+
range.location + range.length, objects.count()),
8080
"Array index out of range")
8181

8282
// These objects are "returned" at +0, so treat them as values to
@@ -105,7 +105,7 @@ extension _SwiftNativeNSArrayWithContiguousStorage: _NSArrayCoreType {
105105
AutoreleasingUnsafeMutablePointer<AnyObject?>.self)
106106
enumerationState.state = 1
107107
state.memory = enumerationState
108-
return objects.count
108+
return objects.count()
109109
}
110110
}
111111

@@ -215,7 +215,7 @@ extension _SwiftNativeNSArrayWithContiguousStorage: _NSArrayCoreType {
215215
}
216216

217217
// Check if elements are bridged verbatim.
218-
return _nativeStorage._withVerbatimBridgedUnsafeBuffer { $0.count }
218+
return _nativeStorage._withVerbatimBridgedUnsafeBuffer { $0.count() }
219219
?? _nativeStorage._getNonVerbatimBridgedCount()
220220
}
221221
}

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public struct Unsafe${Mutable}BufferPointer<T> : ${Mutable}CollectionType {
8787
}
8888

8989
/// The number of elements in the buffer
90-
public var count: Int {
90+
public func count() -> Int {
9191
return _end - _position
9292
}
9393

test/1_stdlib/Algorithm.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ func makeQSortKiller(len: Int) -> [Int] {
359359
func Compare(x: Int, y : Int) -> Bool {
360360
if keys[x] == nil && keys[y] == nil {
361361
if (x == candidate) {
362-
keys[x] = keys.count
362+
keys[x] = keys.count()
363363
} else {
364-
keys[y] = keys.count
364+
keys[y] = keys.count()
365365
}
366366
}
367367
if keys[x] == nil {

0 commit comments

Comments
 (0)