Skip to content

Commit

Permalink
Revert "Remove Array.count, it is redundant with protocol extensions"
Browse files Browse the repository at this point in the history
This reverts commit r28247 while we discuss the change.

Swift SVN r28292
  • Loading branch information
gribozavr committed May 7, 2015
1 parent 10ab07a commit 8b392ee
Show file tree
Hide file tree
Showing 37 changed files with 184 additions and 168 deletions.
4 changes: 2 additions & 2 deletions stdlib/private/StdlibUnittest/RaceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func _masterThreadOneTrial<RT : RaceTestWithPerTrialDataType>(
sharedState.raceData.extend(
lazy(0..<raceDataCount).map { i in rt.makeRaceData() })

let identityShuffle = _UnitTestArray(0..<sharedState.raceData.count())
let identityShuffle = _UnitTestArray(0..<sharedState.raceData.count)
sharedState.workerStates.removeAll(keepCapacity: true)
sharedState.workerStates.extend(
lazy(0..<racingThreadCount).map {
Expand All @@ -433,7 +433,7 @@ func _masterThreadOneTrial<RT : RaceTestWithPerTrialDataType>(
workerState.raceDataShuffle = shuffle

workerState.observations = []
workerState.observations.reserveCapacity(sharedState.raceData.count())
workerState.observations.reserveCapacity(sharedState.raceData.count)

return workerState
})
Expand Down
52 changes: 26 additions & 26 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public struct SourceLocStack {
func _printStackTrace(stackTrace: SourceLocStack?) {
guard let s = stackTrace else { return }
println("stacktrace:")
for i in 0..<s.locs.count() {
let loc = s.locs[s.locs.count() - i - 1]
for i in 0..<s.locs.count {
let loc = s.locs[s.locs.count - i - 1]
let comment = (loc.comment != nil) ? " ; \(loc.comment!)" : ""
println(" #\(i): \(loc.file):\(loc.line)\(comment)")
}
Expand Down Expand Up @@ -746,7 +746,7 @@ struct _ParentProcess {
case (_, .Some(let status), true):
testPassed = !_anyExpectFailed
}
if testPassed && t.crashOutputMatches.count() > 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: () -> ()) {
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -1027,13 +1027,13 @@ func _parseDottedVersion(s: String) -> _UnitTestArray<Int> {

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 {
Expand Down Expand Up @@ -1588,7 +1588,7 @@ public func check${traversal}Collection<
}

if expectedArray.count() >= 2 {
for i in 0..<allIndices.count()-1 {
for i in 0..<allIndices.count-1 {
var successor1 = allIndices[i].successor()
var successor2 = allIndices[i]
successor2++
Expand All @@ -1606,7 +1606,7 @@ public func check${traversal}Collection<
}
}
% if traversal == "Bidirectional":
for i in 1..<allIndices.count() {
for i in 1..<allIndices.count {
var predecessor1 = allIndices[i].predecessor()
var predecessor2 = allIndices[i]
predecessor2--
Expand All @@ -1622,7 +1622,7 @@ public func check${traversal}Collection<
stackTrace: stackTrace.withCurrentLoc())
}
}
for i in 1..<allIndices.count() {
for i in 1..<allIndices.count {
var index = allIndices[i]
--index
++index
Expand Down Expand Up @@ -1745,15 +1745,15 @@ public func checkSliceableWithBidirectionalIndex<
let expectedArray = _UnitTestArray(expected)

var start = sliceable.startIndex
for startNumericIndex in 0...expectedArray.count() {
for startNumericIndex in 0...expectedArray.count {
if start != sliceable.endIndex {
++start
--start
++start
--start
}
var end = start
for endNumericIndex in startNumericIndex...expectedArray.count() {
for endNumericIndex in startNumericIndex...expectedArray.count {
if end != sliceable.endIndex {
++end
--end
Expand Down Expand Up @@ -1821,7 +1821,7 @@ where
a.replaceRange(nthIndex(a, ix)..<nthIndex(a, jx), with: newValues)
let growth = newCount - oldCount

let expectedCount = source.count() + growth
let expectedCount = source.count + growth
let actualCount = numericCast(a.count()) as Int
if actualCount != expectedCount {
reportFailure(
Expand Down Expand Up @@ -2179,7 +2179,7 @@ public struct MinimalGenerator<T> : 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" }
}
Expand Down Expand Up @@ -2235,13 +2235,13 @@ public struct MinimalSequence<T> : 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
Expand Down Expand Up @@ -2403,13 +2403,13 @@ public struct ${Self}<T> : ${'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
Expand Down Expand Up @@ -2477,13 +2477,13 @@ public struct ${Self}<T> : 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
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivate/IO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions stdlib/private/SwiftPrivate/SwiftPrivate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public func scan<

public func randomShuffle<T>(a: _UnitTestArray<T>) -> _UnitTestArray<T> {
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])
Expand All @@ -64,7 +64,7 @@ public func gather<

public func scatter<T>(a: _UnitTestArray<T>, _ idx: _UnitTestArray<Int>) -> _UnitTestArray<T> {
var result = a
for i in 0..<a.count() {
for i in 0..<a.count {
result[idx[i]] = a[i]
}
return result
Expand All @@ -89,7 +89,7 @@ public func withArrayOfCStrings<R>(
(argsBuffer) in
let ptr = UnsafeMutablePointer<CChar>(argsBuffer.baseAddress)
var cStrings = map(argsOffsets) { ptr + $0 }
cStrings[cStrings.count() - 1] = nil
cStrings[cStrings.count - 1] = nil
return body(cStrings)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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..<count {
Expand Down
Loading

0 comments on commit 8b392ee

Please sign in to comment.