diff --git a/stdlib/private/StdlibUnittest/RaceTest.swift b/stdlib/private/StdlibUnittest/RaceTest.swift index 70fd03ae7053f..2c138989193d1 100644 --- a/stdlib/private/StdlibUnittest/RaceTest.swift +++ b/stdlib/private/StdlibUnittest/RaceTest.swift @@ -420,7 +420,7 @@ func _masterThreadOneTrial( sharedState.raceData.extend( lazy(0..( workerState.raceDataShuffle = shuffle workerState.observations = [] - workerState.observations.reserveCapacity(sharedState.raceData.count()) + workerState.observations.reserveCapacity(sharedState.raceData.count) return workerState }) diff --git a/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb b/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb index 8863aa904de0c..474dc10f1a89c 100644 --- a/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb +++ b/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb @@ -77,8 +77,8 @@ public struct SourceLocStack { func _printStackTrace(stackTrace: SourceLocStack?) { guard let s = stackTrace else { return } println("stacktrace:") - for i in 0.. 0 { + if testPassed && t.crashOutputMatches.count > 0 { // If we still think that the test passed, check if the crash // output matches our expectations. let crashOutput = crashStdout + crashStderr @@ -828,7 +828,7 @@ public func runAllTests() { } else { var runTestsInProcess: Bool = false var filter: String? = nil - for var i = 0; i < Process.arguments.count(); { + for var i = 0; i < Process.arguments.count; { let arg = Process.arguments[i] if arg == "--stdlib-unittest-in-process" { runTestsInProcess = true @@ -869,7 +869,7 @@ public class TestSuite { _testNameToIndex[name] == nil, "test suite with the same name already exists") _allTestSuites.append(self) - _testSuiteNameToIndex[name] = _allTestSuites.count() - 1 + _testSuiteNameToIndex[name] = _allTestSuites.count - 1 } public func test(name: String, _ testFunction: () -> ()) { @@ -973,7 +973,7 @@ public class TestSuite { stdinText: _data._stdinText, stdinEndsWithEOF: _data._stdinEndsWithEOF, crashOutputMatches: _data._crashOutputMatches, code: testFunction)) - _testSuite._testNameToIndex[_name] = _testSuite._tests.count() - 1 + _testSuite._testNameToIndex[_name] = _testSuite._tests.count - 1 } } @@ -1027,13 +1027,13 @@ func _parseDottedVersion(s: String) -> _UnitTestArray { public func _parseDottedVersionTriple(s: String) -> (Int, Int, Int) { var array = _parseDottedVersion(s) - if array.count() >= 4 { + if array.count >= 4 { fatalError("unexpected version") } return ( - array.count() >= 1 ? array[0] : 0, - array.count() >= 2 ? array[1] : 0, - array.count() >= 3 ? array[2] : 0) + array.count >= 1 ? array[0] : 0, + array.count >= 2 ? array[1] : 0, + array.count >= 3 ? array[2] : 0) } func _getOSVersion() -> OSVersion { @@ -1588,7 +1588,7 @@ public func check${traversal}Collection< } if expectedArray.count() >= 2 { - for i in 0.. : GeneratorType { } public func next() -> T? { - if _sharedState.i == _sharedState.data.count() { + if _sharedState.i == _sharedState.data.count { if isConsumed { expectUnreachable() { "next() was called on a consumed generator" } } @@ -2235,13 +2235,13 @@ public struct MinimalSequence : SequenceType { switch underestimatedCount { case .Precise: - self._sharedState.underestimatedCount = data.count() + self._sharedState.underestimatedCount = data.count case .Half: - self._sharedState.underestimatedCount = data.count() / 2 + self._sharedState.underestimatedCount = data.count / 2 case .Overestimate: - self._sharedState.underestimatedCount = data.count() * 3 + 5 + self._sharedState.underestimatedCount = data.count * 3 + 5 case .Value(let count): self._sharedState.underestimatedCount = count @@ -2403,13 +2403,13 @@ public struct ${Self} : ${'MutableCollectionType' if mutable else 'Collection switch underestimatedCount { case .Precise: - self.underestimatedCount = _elements.count() + self.underestimatedCount = _elements.count case .Half: - self.underestimatedCount = _elements.count() / 2 + self.underestimatedCount = _elements.count / 2 case .Overestimate: - self.underestimatedCount = _elements.count() * 3 + 5 + self.underestimatedCount = _elements.count * 3 + 5 case .Value(let count): self.underestimatedCount = count @@ -2477,13 +2477,13 @@ public struct ${Self} : RangeReplaceableCollectionType { switch underestimatedCount { case .Precise: - self.underestimatedCount = elements.count() + self.underestimatedCount = elements.count case .Half: - self.underestimatedCount = elements.count() / 2 + self.underestimatedCount = elements.count / 2 case .Overestimate: - self.underestimatedCount = elements.count() * 3 + 5 + self.underestimatedCount = elements.count * 3 + 5 case .Value(let count): self.underestimatedCount = count diff --git a/stdlib/private/SwiftPrivate/IO.swift b/stdlib/private/SwiftPrivate/IO.swift index 8732ee2d97dfe..b5b686c2577ba 100644 --- a/stdlib/private/SwiftPrivate/IO.swift +++ b/stdlib/private/SwiftPrivate/IO.swift @@ -44,7 +44,7 @@ public struct _FDInputStream { public mutating func read() { let minFree = 128 - var bufferFree = _buffer.count() - _bufferUsed + var bufferFree = _buffer.count - _bufferUsed if bufferFree < minFree { _buffer.reserveCapacity(minFree - bufferFree) while bufferFree < minFree { diff --git a/stdlib/private/SwiftPrivate/SwiftPrivate.swift b/stdlib/private/SwiftPrivate/SwiftPrivate.swift index fffe946d3b42b..e0c599eb4e124 100644 --- a/stdlib/private/SwiftPrivate/SwiftPrivate.swift +++ b/stdlib/private/SwiftPrivate/SwiftPrivate.swift @@ -43,7 +43,7 @@ public func scan< public func randomShuffle(a: _UnitTestArray) -> _UnitTestArray { var result = a - for var i = a.count() - 1; i != 0; --i { + for var i = a.count - 1; i != 0; --i { // FIXME: 32 bits are not enough in general case! let j = Int(rand32(exclusiveUpperBound: UInt32(i + 1))) swap(&result[i], &result[j]) @@ -64,7 +64,7 @@ public func gather< public func scatter(a: _UnitTestArray, _ idx: _UnitTestArray) -> _UnitTestArray { var result = a - for i in 0..( (argsBuffer) in let ptr = UnsafeMutablePointer(argsBuffer.baseAddress) var cStrings = map(argsOffsets) { ptr + $0 } - cStrings[cStrings.count() - 1] = nil + cStrings[cStrings.count - 1] = nil return body(cStrings) } } diff --git a/stdlib/private/SwiftPrivateDarwinExtras/SwiftPrivateDarwinExtras.swift b/stdlib/private/SwiftPrivateDarwinExtras/SwiftPrivateDarwinExtras.swift index 65382c411665d..32063f4ebc18b 100644 --- a/stdlib/private/SwiftPrivateDarwinExtras/SwiftPrivateDarwinExtras.swift +++ b/stdlib/private/SwiftPrivateDarwinExtras/SwiftPrivateDarwinExtras.swift @@ -66,7 +66,7 @@ public struct _stdlib_fd_set { } public mutating func zero() { - let count = _data.count() + let count = _data.count return _data.withUnsafeMutableBufferPointer { (_data) in for i in 0.. Bool { - return _bytes.count() >= _consumedCount + count + return _bytes.count >= _consumedCount + count } internal func _lookByte() -> UInt8? { @@ -640,6 +640,10 @@ public struct MsgPackVariantArray : CollectionType { public subscript(i: Int) -> MsgPackVariant { return _data[i] } + + public var count: Int { + return _data.count + } } public struct MsgPackVariantMap : CollectionType { @@ -674,6 +678,10 @@ public struct MsgPackVariantMap : CollectionType { return _data[i] } + public var count: Int { + return _data.count + } + internal mutating func _append( key newKey: MsgPackVariant, value newValue: MsgPackVariant ) { @@ -723,18 +731,18 @@ public enum MsgPackVariant { encoder.append(dataBytes) case Array(let a): - encoder.beginArray(a.count()) + encoder.beginArray(a.count) // Reserve space assuming homogenous arrays. - if !a.isEmpty { + if a.count != 0 { switch a[0] { case .Float32: encoder.bytes.reserveCapacity( - encoder.bytes.count() + a.count() * 5) + encoder.bytes.count + a.count * 5) case .Int64, .UInt64, .Float64: encoder.bytes.reserveCapacity( - encoder.bytes.count() + a.count() * 9) + encoder.bytes.count + a.count * 9) default: () @@ -746,7 +754,7 @@ public enum MsgPackVariant { encoder.endArray() case Map(let m): - encoder.beginMap(m.count()) + encoder.beginMap(m.count) for (key, value) in m { key._serializeToImpl(&encoder) value._serializeToImpl(&encoder) diff --git a/stdlib/private/SwiftPrivateSerialization/MsgPackSerialization.swift.gyb b/stdlib/private/SwiftPrivateSerialization/MsgPackSerialization.swift.gyb index 88adc0dc141fa..cd3e64a831cc3 100644 --- a/stdlib/private/SwiftPrivateSerialization/MsgPackSerialization.swift.gyb +++ b/stdlib/private/SwiftPrivateSerialization/MsgPackSerialization.swift.gyb @@ -251,7 +251,7 @@ internal func _fromMsgPackVariant< % end case .Array(let a): var elements: [Value.Generator.Element] = [] - elements.reserveCapacity(a.count()) + elements.reserveCapacity(a.count) for e in a { var element = Value.Generator.Element(forDeserialization: ()) var deserializerImpl = _MsgPackDeserializerImpl(e) diff --git a/stdlib/public/SDK/Foundation/Foundation.swift b/stdlib/public/SDK/Foundation/Foundation.swift index e34465b3346c7..feb8bb8549a93 100644 --- a/stdlib/public/SDK/Foundation/Foundation.swift +++ b/stdlib/public/SDK/Foundation/Foundation.swift @@ -533,7 +533,7 @@ extension NSDictionary : DictionaryLiteralConvertible { self.init( objects: elements.map { (AnyObject?)($0.1) }, forKeys: elements.map { (NSCopying?)($0.0) }, - count: elements.count()) + count: elements.count) } } @@ -1148,7 +1148,7 @@ extension NSDictionary { // - (instancetype)initWithObjects:(NSArray *)objects forKeys:(NSArray *)keys; var values: [AnyObject] = [] var keys: [AnyObject] = [] - for var i = 0; i < objects.count(); i += 2 { + for var i = 0; i < objects.count; i += 2 { values.append(objects[i]) keys.append(objects[i+1]) } diff --git a/stdlib/public/SDK/Foundation/NSStringAPI.swift b/stdlib/public/SDK/Foundation/NSStringAPI.swift index fd44a06d942df..7bd909478a7b1 100644 --- a/stdlib/public/SDK/Foundation/NSStringAPI.swift +++ b/stdlib/public/SDK/Foundation/NSStringAPI.swift @@ -21,7 +21,7 @@ // func _toNSArray(a: [T], @noescape f: (T) -> U) -> NSArray { - var result = NSMutableArray(capacity: a.count()) + var result = NSMutableArray(capacity: a.count) for s in a { result.addObject(f(s)) } @@ -629,7 +629,7 @@ extension String { return _withOptionalOutParameter(remainingRange) { self._ns.getBytes( &buffer, - maxLength: min(buffer.count(), maxLength), + maxLength: min(buffer.count, maxLength), usedLength: usedLength, encoding: encoding, options: options, @@ -649,7 +649,7 @@ extension String { public func getCString( inout buffer: [CChar], maxLength: Int, encoding: NSStringEncoding ) -> Bool { - return _ns.getCString(&buffer, maxLength: min(buffer.count(), maxLength), + return _ns.getCString(&buffer, maxLength: min(buffer.count, maxLength), encoding: encoding) } @@ -664,7 +664,7 @@ extension String { public func getFileSystemRepresentation( inout buffer: [CChar], maxLength: Int) -> Bool { return _ns.getFileSystemRepresentation( - &buffer, maxLength: min(buffer.count(), maxLength)) + &buffer, maxLength: min(buffer.count, maxLength)) } // - (void) @@ -744,7 +744,7 @@ extension String { ) { let byteArray = Array(bytes) if let ns = NSString( - bytes: byteArray, length: byteArray.count(), encoding: encoding) { + bytes: byteArray, length: byteArray.count, encoding: encoding) { self = ns as String } else { @@ -881,7 +881,7 @@ extension String { /// values are substituted according to given locale information. public init(format: String, locale: NSLocale?, arguments: [CVarArgType]) { _precondition( - _countFormatSpecifiers(format) <= arguments.count(), + _countFormatSpecifiers(format) <= arguments.count, "Too many format specifiers (%) provided for the argument list" ) self = withVaList(arguments) { diff --git a/stdlib/public/SDK/SceneKit/SceneKit.swift b/stdlib/public/SDK/SceneKit/SceneKit.swift index 1009f0b4731d2..757d941e8544e 100644 --- a/stdlib/public/SDK/SceneKit/SceneKit.swift +++ b/stdlib/public/SDK/SceneKit/SceneKit.swift @@ -18,7 +18,7 @@ extension SCNGeometryElement { public convenience init( indices: [IndexType], primitiveType: SCNGeometryPrimitiveType ) { - let indexCount = indices.count() + let indexCount = indices.count let primitiveCount: Int switch primitiveType { case .Triangles: diff --git a/stdlib/public/SDK/simd/simd.swift.gyb b/stdlib/public/SDK/simd/simd.swift.gyb index 2719628b3ca9e..9dfd1f21e8ab6 100644 --- a/stdlib/public/SDK/simd/simd.swift.gyb +++ b/stdlib/public/SDK/simd/simd.swift.gyb @@ -175,7 +175,7 @@ extension ${vectype}: SIMDVectorType { /// - precondition: the array must have the correct number of elements for /// the vector type. public init(_ array: [Scalar]) { - _precondition(array.count() == ${size}, + _precondition(array.count == ${size}, "${vectype} requires a ${cardinals[size]}-element array") self.init(${', '.join(map(lambda i: components[i] + ':array[' + str(i) + ']', @@ -843,7 +843,7 @@ extension ${mattype} : SIMDMatrixType { /// Initialize matrix to have specified `columns`. public init(_ columns: [Column]) { - _precondition(columns.count() == ${cols}, "Requires array of ${cols} vectors") + _precondition(columns.count == ${cols}, "Requires array of ${cols} vectors") % for i in range(cols): self._columns.${i} = columns[${i}] % end @@ -851,7 +851,7 @@ extension ${mattype} : SIMDMatrixType { /// Initialize matrix to have specified `rows`. public init(rows: [Row]) { - _precondition(rows.count() == ${rows}, "Requires array of ${rows} vectors") + _precondition(rows.count == ${rows}, "Requires array of ${rows} vectors") % for i in range(cols): self._columns.${i} = [${', '.join(map(lambda j: 'rows[' + str(j) + '].' + components[i], diff --git a/stdlib/public/core/ArrayCast.swift b/stdlib/public/core/ArrayCast.swift index f34409b0e28a0..689a25e365af1 100644 --- a/stdlib/public/core/ArrayCast.swift +++ b/stdlib/public/core/ArrayCast.swift @@ -73,7 +73,7 @@ public func _arrayForceCast( case (.Value, .Verbatim): var buf = _ContiguousArrayBuffer( - count: source.count(), minimumCapacity: 0) + count: source.count, minimumCapacity: 0) let _: Void = buf.withUnsafeMutableBufferPointer { var p = $0.baseAddress @@ -149,7 +149,7 @@ internal func _arrayConditionalBridgeElements( _sanityCheck(!_isBridgedVerbatimToObjectiveC(TargetElement.self)) var buf = _ContiguousArrayBuffer( - count: source.count(), minimumCapacity: 0) + count: source.count, minimumCapacity: 0) var p = buf.baseAddress diff --git a/stdlib/public/core/ArrayType.swift b/stdlib/public/core/ArrayType.swift index 4b624e382e165..2004ed2f663ab 100644 --- a/stdlib/public/core/ArrayType.swift +++ b/stdlib/public/core/ArrayType.swift @@ -11,7 +11,7 @@ //===----------------------------------------------------------------------===// public protocol __ArrayType : CollectionType { - func count() -> Int + var count: Int {get} typealias _Buffer : _ArrayBufferType var _buffer: _Buffer {get} @@ -41,6 +41,9 @@ protocol _ArrayType /// Construct an array of count elements, each initialized to repeatedValue init(count: Int, repeatedValue: Self.Generator.Element) + /// How many elements the Array stores + var count: Int {get} + /// How many elements the Array can store without reallocation var capacity: Int {get} @@ -133,7 +136,7 @@ internal struct _ArrayTypeMirror : MirrorType { var objectIdentifier: ObjectIdentifier? { return nil } - var count: Int { return _value.count() } + var count: Int { return _value.count } subscript(i: Int) -> (String, MirrorType) { _precondition(i >= 0 && i < count, "MirrorType access out of bounds") diff --git a/stdlib/public/core/Arrays.swift.gyb b/stdlib/public/core/Arrays.swift.gyb index b0ebe8a706dbc..be234b24adddc 100644 --- a/stdlib/public/core/Arrays.swift.gyb +++ b/stdlib/public/core/Arrays.swift.gyb @@ -321,7 +321,7 @@ public struct ${Self} var newBuffer = _ContiguousArrayBuffer( count: buffer.count, minimumCapacity: buffer.count) let target = buffer._uninitializedCopy( - 0.. /// Check that the given `index` is valid, i.e. `0 ≤ index ≤ count` @_semantics("array.check_index") func _checkIndex(index: Int) { - _precondition(index <= self.count(), "${Self} index out of range") + _precondition(index <= count, "${Self} index out of range") _precondition(index >= 0, "Negative ${Self} index is out of range") } @@ -483,6 +483,11 @@ extension ${Self} : _ArrayType { return (result, result._buffer.baseAddress) } + /// How many elements the ${Self} stores + public var count: Int { + return _getCount() + } + /// How many elements the `${Self}` can store without reallocation public var capacity: Int { return _getCapacity() @@ -519,9 +524,9 @@ extension ${Self} : _ArrayType { if _buffer.requestUniqueMutableBackingBuffer(minimumCapacity) == nil { var newBuffer = _ContiguousArrayBuffer( - count: self.count(), minimumCapacity: minimumCapacity) + count: count, minimumCapacity: minimumCapacity) - _buffer._uninitializedCopy(0..= minimumCapacity) @@ -580,8 +585,8 @@ extension ${Self} : _ArrayType { /// Remove an element from the end of the ${Self} in O(1). /// Requires: count > 0 public mutating func removeLast() -> T { - let c = self.count() - _precondition(c > 0, "can't removeLast from an empty ${Self}") + _precondition(count > 0, "can't removeLast from an empty ${Self}") + let c = count // We don't check for "c - 1" underflow because C is known to be positive. let result = self[c &- 1] self.replaceRange((c &- 1)..(inout lhs: ${Self}, rhs: S) { - let oldCount = lhs.count() + let oldCount = lhs.count let capacity = lhs.capacity let newCount = oldCount + rhs.underestimateCount() @@ -990,7 +995,7 @@ where C.Generator.Element == T >(inout lhs: ${Self}, rhs: C) { let rhsCount = numericCast(rhs.count()) as Int - let oldCount = lhs.count() + let oldCount = lhs.count let capacity = lhs.capacity let newCount = oldCount + rhsCount @@ -1187,8 +1192,8 @@ func _arrayAppendSequence< /// Returns true if these arrays contain the same elements. public func ==(lhs: ${Self}, rhs: ${Self}) -> Bool { - let lhsCount = lhs.count() - if lhsCount != rhs.count() { + let lhsCount = lhs.count + if lhsCount != rhs.count { return false } diff --git a/stdlib/public/core/Collection.swift b/stdlib/public/core/Collection.swift index a7106f5734b2a..298c78952ee5d 100644 --- a/stdlib/public/core/Collection.swift +++ b/stdlib/public/core/Collection.swift @@ -179,7 +179,7 @@ public func ~> >( let s = source._baseAddressIfContiguous if s != nil { let p = UnsafeMutablePointer(ptr.1) - p.initializeFrom(s, count: source.count()) + p.initializeFrom(s, count: source.count) _fixLifetime(source._owner) } else { var p = UnsafeMutablePointer(ptr.1) diff --git a/stdlib/public/core/HashedCollections.swift.gyb b/stdlib/public/core/HashedCollections.swift.gyb index 33e37a60273e9..1d2e0ab6413d3 100644 --- a/stdlib/public/core/HashedCollections.swift.gyb +++ b/stdlib/public/core/HashedCollections.swift.gyb @@ -1896,7 +1896,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> : ) -> _Native${Self}Storage<${TypeParameters}> { let requiredCapacity = _Native${Self}Storage<${TypeParameters}>.getMinCapacity( - elements.count(), _hashContainerDefaultMaxLoadFactorInverse) + elements.count, _hashContainerDefaultMaxLoadFactorInverse) var nativeStorage = _Native${Self}Storage<${TypeParameters}>( minimumCapacity: requiredCapacity) @@ -1920,7 +1920,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> : _precondition(!found, "${Self} literal contains duplicate keys") nativeStorage[i.offset] = Element(key: key, value: value) } - nativeStorage.count = elements.count() + nativeStorage.count = elements.count %end diff --git a/stdlib/public/core/SequenceAlgorithms.swift.gyb b/stdlib/public/core/SequenceAlgorithms.swift.gyb index fc142634ece9b..f4eeb012c8bf3 100644 --- a/stdlib/public/core/SequenceAlgorithms.swift.gyb +++ b/stdlib/public/core/SequenceAlgorithms.swift.gyb @@ -342,7 +342,7 @@ extension SequenceType { // optimized to a memcpy() sometimes. Those cases are usually collections, // though. var result = Array(self) - let count = result.count() + let count = result.count for i in 0.. Bool in true } expectEqual([ 0, 30, 10, 90 ], result) expectEqual([], Array(s)) { "sequence should be consumed" } - expectGE(2 * result.count(), result.capacity) + expectGE(2 * result.count, result.capacity) } if true { let s = MinimalSequence( @@ -142,7 +142,7 @@ Algorithm.test("filter/SequenceType") { let result = filter(s) { $0 % 3 == 0 } expectEqual([ 0, 30, 90 ], result) expectEqual([], Array(s)) { "sequence should be consumed" } - expectGE(2 * result.count(), result.capacity) + expectGE(2 * result.count, result.capacity) } if true { let s = MinimalSequence( @@ -150,7 +150,7 @@ Algorithm.test("filter/SequenceType") { let result = filter(s) { $0 % 3 == 0 } expectEqual([ 0, 30, 90 ], result) expectEqual([], Array(s)) { "sequence should be consumed" } - expectGE(2 * result.count(), result.capacity) + expectGE(2 * result.count, result.capacity) } } @@ -178,13 +178,13 @@ Algorithm.test("filter/CollectionType") { let c = MinimalForwardCollection([ 0, 30, 10, 90 ]) let result = filter(c) { (x: Int) -> Bool in true } expectEqual([ 0, 30, 10, 90 ], result) - expectGE(2 * result.count(), result.capacity) + expectGE(2 * result.count, result.capacity) } if true { let c = MinimalForwardCollection([ 0, 30, 10, 90 ]) let result = filter(c) { $0 % 3 == 0 } expectEqual([ 0, 30, 90 ], result) - expectGE(2 * result.count(), result.capacity) + expectGE(2 * result.count, result.capacity) } } @@ -282,7 +282,7 @@ struct A : MutableSliceable { } var endIndex: Int { - return impl.count() + return impl.count } func generate() -> Array.Generator { @@ -291,24 +291,24 @@ struct A : MutableSliceable { subscript(i: Int) -> T { get { - expectTrue(i >= 0 && i < impl.count()) + expectTrue(i >= 0 && i < impl.count) return impl[i] } set (x) { - expectTrue(i >= 0 && i < impl.count()) + expectTrue(i >= 0 && i < impl.count) impl[i] = x } } subscript(r: Range) -> Array.SubSlice { get { - expectTrue(r.startIndex >= 0 && r.startIndex <= impl.count()) - expectTrue(r.endIndex >= 0 && r.endIndex <= impl.count()) + expectTrue(r.startIndex >= 0 && r.startIndex <= impl.count) + expectTrue(r.endIndex >= 0 && r.endIndex <= impl.count) return impl[r] } set (x) { - expectTrue(r.startIndex >= 0 && r.startIndex <= impl.count()) - expectTrue(r.endIndex >= 0 && r.endIndex <= impl.count()) + expectTrue(r.startIndex >= 0 && r.startIndex <= impl.count) + expectTrue(r.endIndex >= 0 && r.endIndex <= impl.count) impl[r] = x } } @@ -583,7 +583,7 @@ SequenceTypeAlgorithms.test("${algorithmKind}Element/Predicate") { stackTrace: test.loc.withCurrentLoc()) } expectEqual([], s._prext_map { $0.value }) { "sequence should be consumed" } - expectEqual(max(0, test.sequence.count() - 1), timesClosureWasCalled) { + expectEqual(max(0, test.sequence.count - 1), timesClosureWasCalled) { "maxElement() should be eager and should only call its predicate once per element" } } @@ -1176,7 +1176,7 @@ SequenceTypeAlgorithms.test("reduce") { } expectEqual(test.sequence, result.value) expectEqual([], s._prext_map { $0.value }) { "sequence should be consumed" } - expectEqual(test.sequence.count(), timesClosureWasCalled) { + expectEqual(test.sequence.count, timesClosureWasCalled) { "reduce() should be eager and should only call its predicate once per element" } } @@ -1347,10 +1347,10 @@ SequenceTypeAlgorithms.test("filter/SequenceType/${dispatch}") { expectType([OpaqueValue].self, &result) expectEqual(test.expected, map(result) { $0.value }) expectEqual([], s._prext_map { $0.value }) { "sequence should be consumed" } - expectEqual(test.sequence.count(), timesClosureWasCalled) { + expectEqual(test.sequence.count, timesClosureWasCalled) { "filter() should be eager and should only call its predicate once per element" } - expectGE(2 * result.count(), result.capacity) { + expectGE(2 * result.count, result.capacity) { "filter() should not reserve capacity (it does not know how much the predicate will filter out)" } } @@ -1537,7 +1537,7 @@ SequenceTypeAlgorithms.test("filter/RangeReplaceableCollectionType/${CollectionT expectEqual(test.sequence, s._prext_map { $0.value }) { "collection should not be consumed" } - expectEqual(test.sequence.count(), timesClosureWasCalled) { + expectEqual(test.sequence.count, timesClosureWasCalled) { "filter() should be eager and should only call its predicate once per element" } expectGE(2 * result.count(), result.${'capacity' if CollectionKind == 'StdlibArray' else 'reservedCapacity'}) { @@ -1609,7 +1609,7 @@ SequenceTypeAlgorithms.test("map/SequenceType") { expectType([OpaqueValue].self, &result) expectEqual(test.expected, result._prext_map { $0.value }) expectEqual([], s._prext_map { $0.value }) { "sequence should be consumed" } - expectEqual(test.sequence.count(), timesClosureWasCalled) { + expectEqual(test.sequence.count, timesClosureWasCalled) { "map() should be eager and should only call its predicate once per element" } } @@ -1642,7 +1642,7 @@ SequenceTypeAlgorithms.test("map/CollectionType") { expectEqual(test.sequence, s._prext_map { $0.value }) { "collection should not be consumed" } - expectEqual(test.sequence.count(), timesClosureWasCalled) { + expectEqual(test.sequence.count, timesClosureWasCalled) { "map() should be eager and should only call its predicate once per element" } } @@ -1735,7 +1735,7 @@ SequenceTypeAlgorithms.test("flatMap/SequenceType") { test.expected, result._prext_map { $0.value }, stackTrace: test.loc.withCurrentLoc()) expectEqual([], s._prext_map { $0.value }) { "sequence should be consumed" } - expectEqual(test.sequence.count(), timesClosureWasCalled) { + expectEqual(test.sequence.count, timesClosureWasCalled) { "map() should be eager and should only call its predicate once per element" } expectGE(2 * result.count(), result.capacity) { @@ -1812,7 +1812,7 @@ SequenceTypeAlgorithms.test("flatMap/SequenceType/TransformProducesOptional") { test.expected, result._prext_map { $0.value }, stackTrace: test.loc.withCurrentLoc()) expectEqual([], s._prext_map { $0.value }) { "sequence should be consumed" } - expectEqual(test.sequence.count(), timesClosureWasCalled) { + expectEqual(test.sequence.count, timesClosureWasCalled) { "flatMap() should be eager and should only call its predicate once per element" } expectGE(2 * result.count(), result.capacity) { @@ -2834,7 +2834,7 @@ func forAllPermutations( sequence: S, body: ([S.Generator.Element]) -> () ) { let data = Array(sequence) - forAllPermutations(data.count()) { + forAllPermutations(data.count) { (indices: [Int]) in body(indices._prext_map { data[$0] }) return () @@ -2998,7 +2998,7 @@ SequenceTypeAlgorithms.test("partition/${'Predicate' if predicate else 'WhereEle if true { % if predicate: var sequenceAsArray: [OpaqueValue] = - zip(sequence, 0..) { _storage = a - _reservedCapacity = a.count() + _reservedCapacity = a.count } func generate() -> Array.Generator { diff --git a/test/1_stdlib/NSStringAPI.swift b/test/1_stdlib/NSStringAPI.swift index 3dbdb78f609b0..487899bd41bf2 100644 --- a/test/1_stdlib/NSStringAPI.swift +++ b/test/1_stdlib/NSStringAPI.swift @@ -37,7 +37,7 @@ class NonContiguousNSString : NSString { } @objc override var length: Int { - return _value.count() + return _value.count } @objc override func characterAtIndex(index: Int) -> unichar { @@ -64,7 +64,7 @@ var NSStringAPIs = TestSuite("NSStringAPIs") NSStringAPIs.test("Encodings") { let availableEncodings: [NSStringEncoding] = String.availableStringEncodings() - expectNotEqual(0, availableEncodings.count()) + expectNotEqual(0, availableEncodings.count) let defaultCStringEncoding = String.defaultCStringEncoding() expectTrue(availableEncodings.contains(defaultCStringEncoding)) @@ -426,7 +426,7 @@ NSStringAPIs.test("enumerateLines(_:)") { (line: String, inout stop: Bool) in lines.append(line) - if lines.count() == 3 { + if lines.count == 3 { stop = true } } @@ -449,7 +449,7 @@ NSStringAPIs.test("enumerateLinguisticTagsInRange(_:scheme:options:orthography:_ tags.append(tag) tokens.append(s[tokenRange]) sentences.append(s[sentenceRange]) - if tags.count() == 3 { + if tags.count == 3 { stop = true } } @@ -523,7 +523,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain // 'maxLength' is limiting. let bufferLength = 100 var expectedStr: [UInt8] = Array("def где ".utf8) - while expectedStr.count() != bufferLength { + while (expectedStr.count != bufferLength) { expectedStr.append(0xff) } var buffer = [UInt8](count: bufferLength, repeatedValue: 0xff) @@ -544,7 +544,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain // completely, since doing that would break a UTF sequence. let bufferLength = 5 var expectedStr: [UInt8] = Array("def ".utf8) - while expectedStr.count() != bufferLength { + while (expectedStr.count != bufferLength) { expectedStr.append(0xff) } var buffer = [UInt8](count: bufferLength, repeatedValue: 0xff) @@ -564,7 +564,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain // 'range' is converted completely. let bufferLength = 100 var expectedStr: [UInt8] = Array("def где gh жз ".utf8) - while expectedStr.count() != bufferLength { + while (expectedStr.count != bufferLength) { expectedStr.append(0xff) } var buffer = [UInt8](count: bufferLength, repeatedValue: 0xff) @@ -584,7 +584,7 @@ NSStringAPIs.test("getBytes(_:maxLength:usedLength:encoding:options:range:remain // Inappropriate encoding. let bufferLength = 100 var expectedStr: [UInt8] = Array("def ".utf8) - while expectedStr.count() != bufferLength { + while (expectedStr.count != bufferLength) { expectedStr.append(0xff) } var buffer = [UInt8](count: bufferLength, repeatedValue: 0xff) @@ -617,7 +617,7 @@ NSStringAPIs.test("getCString(_:maxLength:encoding:)") { // The smallest buffer where the result can fit. let bufferLength = 17 var expectedStr = map("abc あかさた\0".utf8) { CChar(bitPattern: $0) } - while expectedStr.count() != bufferLength { + while (expectedStr.count != bufferLength) { expectedStr.append(CChar(bitPattern: 0xff)) } var buffer = Array( @@ -666,7 +666,7 @@ NSStringAPIs.test("getFileSystemRepresentation(_:maxLength:)") { var expectedStr = map("abc \u{305f}\u{3099}くてん\0".utf8) { CChar(bitPattern: $0) } - while expectedStr.count() != bufferLength { + while (expectedStr.count != bufferLength) { expectedStr.append(CChar(bitPattern: 0xff)) } var buffer = Array( @@ -743,7 +743,7 @@ NSStringAPIs.test("init(bytes:encoding:)") { FIXME: Test disabled because the NSString documentation is unclear about what should actually happen in this case. - expectEmpty(String(bytes: bytes, length: bytes.count(), + expectEmpty(String(bytes: bytes, length: bytes.count, encoding: NSASCIIStringEncoding)) */ @@ -754,14 +754,14 @@ NSStringAPIs.test("init(bytesNoCopy:length:encoding:freeWhenDone:)") { var s: String = "abc あかさた" var bytes: [UInt8] = Array(s.utf8) expectOptionalEqual(s, String(bytesNoCopy: &bytes, - length: bytes.count(), encoding: NSUTF8StringEncoding, + length: bytes.count, encoding: NSUTF8StringEncoding, freeWhenDone: false)) /* FIXME: Test disabled because the NSString documentation is unclear about what should actually happen in this case. - expectEmpty(String(bytesNoCopy: &bytes, length: bytes.count(), + expectEmpty(String(bytesNoCopy: &bytes, length: bytes.count, encoding: NSASCIIStringEncoding, freeWhenDone: false)) */ @@ -772,7 +772,7 @@ NSStringAPIs.test("init(utf16CodeUnits:count:)") { let expected = "abc абв \u{0001F60A}" let chars: [unichar] = Array(expected.utf16) - expectEqual(expected, String(utf16CodeUnits: chars, count: chars.count())) + expectEqual(expected, String(utf16CodeUnits: chars, count: chars.count)) } NSStringAPIs.test("init(utf16CodeUnitsNoCopy:count:freeWhenDone:)") { @@ -780,7 +780,7 @@ NSStringAPIs.test("init(utf16CodeUnitsNoCopy:count:freeWhenDone:)") { let chars: [unichar] = Array(expected.utf16) expectEqual(expected, String(utf16CodeUnitsNoCopy: chars, - count: chars.count(), freeWhenDone: false)) + count: chars.count, freeWhenDone: false)) } NSStringAPIs.test("init(format:_:...)") { diff --git a/test/1_stdlib/NewArray.swift.gyb b/test/1_stdlib/NewArray.swift.gyb index e886f914f18d9..a46be1a61ef71 100644 --- a/test/1_stdlib/NewArray.swift.gyb +++ b/test/1_stdlib/NewArray.swift.gyb @@ -120,7 +120,7 @@ where T.Generator.Element == T._Buffer.Element, checkEqual(x, 1...5, true) - x.reserveCapacity(x.count() + 2) + x.reserveCapacity(x.count + 2) checkEqual(x, 1...5, true) let bufferId0 = bufferID(x) @@ -129,7 +129,7 @@ where T.Generator.Element == T._Buffer.Element, x += 0..<2 let bufferId1 = checkReallocation(x, bufferId0, false) - for i in x.count()..<(x.capacity + 1) { + for i in x.count..<(x.capacity + 1) { let bufferId1a = checkReallocation(x, bufferId1, false) x.append(13) } @@ -149,7 +149,7 @@ where T.Generator.Element == T._Buffer.Element, // It's possible that factor will change, but (cursory) testing // has shown that using 1.5, the other popular growth factor, // slows things down. - for _ in a.count()..<(a.capacity * 4) { + for _ in a.count..<(a.capacity * 4) { let oldId = bufferID(a) growBy1(&a) if oldId != bufferID(a) { @@ -223,7 +223,7 @@ func nsArrayOfStrings() -> Array { let src: ContiguousArray = ["foo", "bar", "baz"] return src.withUnsafeBufferPointer { - let ns = NSArray(objects: UnsafePointer($0.baseAddress), count: $0.count()) + let ns = NSArray(objects: UnsafePointer($0.baseAddress), count: $0.count) return _convertNSArrayToArray(ns) } } @@ -291,7 +291,7 @@ func testSlice() { // ArraySlice it var bSlice = b[3..<5] - println("<\(bSlice.count())>") + println("<\(bSlice.count)>") // CHECK-NEXT: <2> println("bSlice0: \(bSlice)") // CHECK-NEXT: bSlice0: [3, 4] @@ -309,7 +309,7 @@ func testSlice() { printSequence(b) // CHECK-NEXT: [0, 1, 2, 3, 41, 5, 6] var c = b - b[4..") // CHECK-NEXT: <3> + println("<\(aSlice.count)>") // CHECK-NEXT: <3> printSequence(aSlice) // CHECK-NEXT: [buzz, baz, fodder] // And doesn't change a @@ -370,7 +370,7 @@ func testReplace${A}( testReplace({ r }) // This test should ensure r's retain isn't dropped before we start testing. - if (r.count() != testWidth) { + if (r.count != testWidth) { println("something bad happened!") } } @@ -386,7 +386,7 @@ for (maxValue, label) in [(testWidth, "trailing"), (testWidth*2, "interior")] { println("testing subrange replacement in \(label) Sub-ArraySlice") testReplaceArraySlice { var a = ContiguousArray(X(-testWidth).. Int { get { return data[i - startIndex] } set { data[i - startIndex] = newValue } @@ -71,7 +71,7 @@ class OffsetCollection : MutableCollectionType { func toArray() -> [Int] { return data } - var count: Int { return data.count() } + var count: Int { return data.count } init(_ ary: [Int], offset: Int, forward: Bool) { data = ary self.offset = offset diff --git a/test/1_stdlib/sort_integers.swift b/test/1_stdlib/sort_integers.swift index 8d161ea372e3d..a45ab91e851fa 100644 --- a/test/1_stdlib/sort_integers.swift +++ b/test/1_stdlib/sort_integers.swift @@ -61,7 +61,7 @@ permute(3, printer) // Now, let's verify the sort. let sort_verifier : ([Int]) -> () = { var y = sorted($0) - for i in 0.. y[i+1]) { println("Error: \(y)") return @@ -80,7 +80,7 @@ println("Test1 - Done") let partition_verifier : ([Int]) -> () = { var y = $0 // Partition() returns the index to the pivot value. - let idx = partition(&y, 0.. () = { } // Check that all of the elements in the second partition are greater or // equal to the pivot value. - for i in idx.. UnsafeMutablePointer { } func constPointerToObjC(objects: [AnyObject?]) -> NSArray { - return NSArray(objects: objects, count: objects.count()) + return NSArray(objects: objects, count: objects.count) } func mutablePointerToObjC(path: String) throws -> NSString { diff --git a/test/DebugInfo/closure.swift b/test/DebugInfo/closure.swift index f878fcddf33a2..4a4843862d93d 100644 --- a/test/DebugInfo/closure.swift +++ b/test/DebugInfo/closure.swift @@ -3,9 +3,9 @@ func markUsed(t: T) {} func foldl1(list: [T], _ function: (a: T, b: T) -> T) -> T { - assert(list.count() > 1) + assert(list.count > 1) var accumulator = list[0] - for var i = 1; i < list.count(); ++i { + for var i = 1; i < list.count; ++i { accumulator = function(a: accumulator, b: list[i]) } return accumulator diff --git a/test/DebugInfo/trap-optimized.swift b/test/DebugInfo/trap-optimized.swift index 9e91d8b4b0f76..a4d375d261e1e 100644 --- a/test/DebugInfo/trap-optimized.swift +++ b/test/DebugInfo/trap-optimized.swift @@ -4,9 +4,9 @@ func fn() { println("two") // CHECK-DAG: ![[LOC:.*]] = !DILocation(line: [[@LINE+1]], column: 13, - println(0 - UInt(Process.arguments.count())) + println(0 - UInt(Process.arguments.count)) // CHECK-DAG: ![[LOC2:.*]] = !DILocation(line: [[@LINE+1]], column: 13, - println(1 - UInt(Process.arguments.count())) + println(1 - UInt(Process.arguments.count)) println("three") } diff --git a/test/Generics/slice_test.swift b/test/Generics/slice_test.swift index ddd74fffe132e..865dd289476c8 100644 --- a/test/Generics/slice_test.swift +++ b/test/Generics/slice_test.swift @@ -18,7 +18,7 @@ infix operator != { } func testslice(s: Array) { - for i in 0..(inout array: [T]) { - for i in 0..(a).memory - UnsafePointer(b).memory) } // CHECK-NEXT: [2, 3, 5, 6, 9, 14, 15] diff --git a/test/Interpreter/SDK/objc_implicit_unwrapped_bridge.swift b/test/Interpreter/SDK/objc_implicit_unwrapped_bridge.swift index 85cabaf37378a..832dbfd96e852 100644 --- a/test/Interpreter/SDK/objc_implicit_unwrapped_bridge.swift +++ b/test/Interpreter/SDK/objc_implicit_unwrapped_bridge.swift @@ -120,7 +120,7 @@ func testConvertToArrayOfImplicitUnwrappedClass() { // CHECK: Class array count = 2 // CHECK: Element 0 has value X(1) // CHECK: Element 1 has value X(2) - println("Class array count = \(arr.count())") + println("Class array count = \(arr.count)") for (index, opt) in arr.enumerate() { if let x = opt { println("Element \(index) has value X(\(x.value))") @@ -144,7 +144,7 @@ func testConvertToArrayOfImplicitUnwrappedString() { // CHECK: String array count = 2 // CHECK: Element 0 has value Hello // CHECK: Element 1 has value World - println("String array count = \(arr.count())") + println("String array count = \(arr.count)") for (index, opt) in arr.enumerate() { if let str = opt { println("Element \(index) has value \(str)") diff --git a/test/Interpreter/tuples.swift b/test/Interpreter/tuples.swift index 806e7e205df13..35809a900760d 100644 --- a/test/Interpreter/tuples.swift +++ b/test/Interpreter/tuples.swift @@ -39,7 +39,7 @@ func mutate() { mutate() func printInts(ints: Int...) { - print("\(ints.count()) ints: ") + print("\(ints.count) ints: ") for int in ints { print("\(int) ") } diff --git a/test/Prototypes/Sequence.swift b/test/Prototypes/Sequence.swift index 2755f12fff686..2b3b9e3071593 100644 --- a/test/Prototypes/Sequence.swift +++ b/test/Prototypes/Sequence.swift @@ -164,7 +164,7 @@ public struct MyArray : Q_CollectionType { } public var endIndex: Int { - return _data.count() + return _data.count } public subscript(index: Int) -> Element { diff --git a/test/SILPasses/dead_func.swift b/test/SILPasses/dead_func.swift index 1236eb2a4c977..23a2d27617f47 100644 --- a/test/SILPasses/dead_func.swift +++ b/test/SILPasses/dead_func.swift @@ -5,7 +5,7 @@ var a : [String] = ["foo"] _preconditionFailure("unreachable") -for i in 0...a.count() { +for i in 0...a.count { let x = 0 } diff --git a/test/decl/subscript/subscripting.swift b/test/decl/subscript/subscripting.swift index 82e054bca149b..65f154bb09033 100644 --- a/test/decl/subscript/subscripting.swift +++ b/test/decl/subscript/subscripting.swift @@ -194,7 +194,7 @@ func subscript_rvalue_materialize(inout i: Int) { func subscript_coerce(fn: ([UnicodeScalar], [UnicodeScalar]) -> Bool) {} func test_subscript_coerce() { - subscript_coerce({ $0[$0.count()-1] < $1[$1.count()-1] }) + subscript_coerce({ $0[$0.count-1] < $1[$1.count-1] }) } struct no_index {