Skip to content

Commit d864cfc

Browse files
committed
Merge pull request #556 from dduan/increment_decrement_search_replace
replace singular statement ++/-- with += 1/-= 1 for integer variables
2 parents 226a825 + ebb0c3a commit d864cfc

Some content is hidden

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

52 files changed

+135
-135
lines changed

stdlib/private/StdlibUnittest/RaceTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ struct _RaceTestAggregatedEvaluations : CustomStringConvertible {
342342
mutating func addEvaluation(evaluation: RaceTestObservationEvaluation) {
343343
switch evaluation {
344344
case .Pass:
345-
++passCount
345+
passCount += 1
346346

347347
case .PassInteresting(let s):
348348
if passInterestingCount[s] == nil {
@@ -351,7 +351,7 @@ struct _RaceTestAggregatedEvaluations : CustomStringConvertible {
351351
passInterestingCount[s] = passInterestingCount[s]! + 1
352352

353353
case .Failure:
354-
++failureCount
354+
failureCount += 1
355355

356356
case .FailureInteresting(let s):
357357
if failureInterestingCount[s] == nil {

stdlib/private/SwiftPrivate/IO.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public struct _FDInputStream {
4949
_buffer.reserveCapacity(minFree - bufferFree)
5050
while bufferFree < minFree {
5151
_buffer.append(0)
52-
++bufferFree
52+
bufferFree += 1
5353
}
5454
}
5555
let readResult: __swift_ssize_t = _buffer.withUnsafeMutableBufferPointer {

stdlib/public/SDK/Foundation/Foundation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ final public class NSFastGenerator : GeneratorType {
696696
if count == 0 { return .None }
697697
}
698698
let next : AnyObject = state[0].itemsPtr[n]!
699-
++n
699+
n += 1
700700
return next
701701
}
702702

stdlib/public/SDK/Foundation/NSStringAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func _countFormatSpecifiers(a: String) -> Int {
5454
lastChar = notPercentUTF16
5555
}
5656
else {
57-
++count
57+
count += 1
5858
lastChar = c
5959
}
6060
} else {
@@ -141,7 +141,7 @@ extension String {
141141
var p = NSString.availableStringEncodings()
142142
while p.memory != 0 {
143143
result.append(p.memory)
144-
++p
144+
p += 1
145145
}
146146
return result
147147
}

stdlib/public/core/ArrayBuffer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ extension _ArrayBuffer {
225225
var result = target
226226
for _ in subRange {
227227
result.initialize(result.memory)
228-
++result
228+
result += 1
229229
}
230230
return result
231231
}

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
663663
mutating func addWithExistingCapacity(element: Element) {
664664
_sanityCheck(remainingCapacity > 0,
665665
"_UnsafePartiallyInitializedContiguousArrayBuffer has no more capacity")
666-
remainingCapacity--
666+
remainingCapacity -= 1
667667

668668
(p++).initialize(element)
669669
}

stdlib/public/core/Reflection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func _dumpWithMirror<TargetStream : OutputStreamType>(
175175
inout _ targetStream: TargetStream
176176
) {
177177
if maxItemCounter <= 0 { return }
178-
--maxItemCounter
178+
maxItemCounter -= 1
179179

180180
for _ in 0..<indent { print(" ", terminator: "", toStream: &targetStream) }
181181

stdlib/public/core/StaticString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public struct StaticString
119119
var i = 0
120120
let sink: (UInt8) -> Void = {
121121
buffer = buffer | (UInt64($0) << (UInt64(i) * 8))
122-
++i
122+
i += 1
123123
}
124124
UTF8.encode(unicodeScalar, output: sink)
125125
return body(UnsafeBufferPointer(

stdlib/public/core/StringUnicodeScalarView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extension String {
7777
let codeUnit = _core[--i]
7878
if _slowPath((codeUnit >> 10) == 0b1101_11) {
7979
if i != 0 && (_core[i - 1] >> 10) == 0b1101_10 {
80-
--i
80+
i -= 1
8181
}
8282
}
8383
return Index(i, _core)

stdlib/public/core/VarArgs.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ final public class VaListBuilder {
398398
+ (sseRegistersUsed * _x86_64SSERegisterWords)
399399
for w in encoded {
400400
storage[startIndex] = w
401-
++startIndex
401+
startIndex += 1
402402
}
403-
++sseRegistersUsed
403+
sseRegistersUsed += 1
404404
}
405405
else if encoded.count == 1 && gpRegistersUsed < _x86_64CountGPRegisters {
406406
storage[gpRegistersUsed++] = encoded[0]

test/1_stdlib/Dispatch.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ DispatchAPI.test("OS_OBJECT support") {
3232
DispatchAPI.test("dispatch_block_t conversions") {
3333
var counter = 0
3434
let closure = { () -> Void in
35-
counter++
35+
counter += 1
3636
}
3737

3838
let block = closure as dispatch_block_t
@@ -59,7 +59,7 @@ if #available(OSX 10.10, iOS 8.0, *) {
5959
var counter = 0
6060

6161
let block = dispatch_block_create(dispatch_block_flags_t(0)) {
62-
counter++
62+
counter += 1
6363
}
6464
block()
6565
expectEqual(1, counter)

test/1_stdlib/ErrorHandling.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ ErrorHandlingTests.test("ErrorHandling/forEach") {
135135
var loopCount = 0
136136
do {
137137
try [1, 2, 3].forEach {
138-
++loopCount
138+
loopCount += 1
139139
if $0 == 2 {
140140
throw SillyError.JazzHands
141141
}
@@ -151,7 +151,7 @@ ErrorHandlingTests.test("ErrorHandling/Optional flatMap") {
151151
var loopCount = 0
152152
do {
153153
let _: [Int] = try [1, 2, 3].flatMap {
154-
++loopCount
154+
loopCount += 1
155155
if $0 == 2 {
156156
throw SillyError.JazzHands
157157
}
@@ -167,7 +167,7 @@ ErrorHandlingTests.test("ErrorHandling/Array flatMap") {
167167
var loopCount = 0
168168
do {
169169
let _: [Int] = try [1, 2, 3].flatMap {(x) -> [Int] in
170-
++loopCount
170+
loopCount += 1
171171
if x == 2 {
172172
throw SillyError.JazzHands
173173
}
@@ -243,7 +243,7 @@ ErrorHandlingTests.test("ErrorHandling/reduce") {
243243
let x: Int = try [1, 2, 3, 4, 5].reduce(0, combine: {
244244
(x: Int, y: Int) -> Int
245245
in
246-
++loopCount
246+
loopCount += 1
247247
var total = x + y
248248
if total > 5 {
249249
throw SillyError.JazzHands
@@ -295,7 +295,7 @@ ErrorHandlingTests.test("ErrorHandling/Sequence map") {
295295
if loopCount == throwAtCount {
296296
throw SillyError.JazzHands
297297
}
298-
++loopCount
298+
loopCount += 1
299299
return Noisy()
300300
}
301301
expectEqual(NoisyCount, initialCount + 3)
@@ -316,7 +316,7 @@ ErrorHandlingTests.test("ErrorHandling/Sequence filter") {
316316
if loopCount == throwAtCount {
317317
throw SillyError.JazzHands
318318
}
319-
++loopCount
319+
loopCount += 1
320320
return condition
321321
}
322322
expectEqual(NoisyCount, initialCount + sequence.count)
@@ -337,7 +337,7 @@ ErrorHandlingTests.test("ErrorHandling/Collection map") {
337337
if loopCount == throwAtCount {
338338
throw SillyError.JazzHands
339339
}
340-
++loopCount
340+
loopCount += 1
341341
return Noisy()
342342
}
343343
expectEqual(NoisyCount, initialCount + 3)

test/1_stdlib/Inputs/DictionaryKeyValueTypes.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,15 @@ struct TestBridgedValueTy : CustomStringConvertible, _ObjectiveCBridgeable {
428428
}
429429

430430
func _bridgeToObjectiveC() -> TestObjCValueTy {
431-
TestBridgedValueTy.bridgeOperations++
431+
TestBridgedValueTy.bridgeOperations += 1
432432
return TestObjCValueTy(value)
433433
}
434434

435435
static func _forceBridgeFromObjectiveC(
436436
x: TestObjCValueTy,
437437
inout result: TestBridgedValueTy?
438438
) {
439-
TestBridgedValueTy.bridgeOperations++
439+
TestBridgedValueTy.bridgeOperations += 1
440440
result = TestBridgedValueTy(x.value)
441441
}
442442

@@ -637,7 +637,7 @@ func slurpFastEnumerationFromSwift(
637637
for i in 0..<returnedCount {
638638
let value: AnyObject = state.itemsPtr[i]!
639639
sink(value)
640-
++itemsReturned
640+
itemsReturned += 1
641641
}
642642
if maxItems != nil && itemsReturned >= maxItems! {
643643
return
@@ -681,7 +681,7 @@ func slurpFastEnumerationFromSwift(
681681
let value: AnyObject = d.objectForKey(key)!
682682
let kv = (key, value)
683683
sink(kv)
684-
++itemsReturned
684+
itemsReturned += 1
685685
}
686686
if maxItems != nil && itemsReturned >= maxItems! {
687687
return
@@ -999,7 +999,7 @@ func slurpFastEnumerationFromSwift(
999999
for i in 0..<returnedCount {
10001000
let value: AnyObject = state.itemsPtr[i]!
10011001
sink(value)
1002-
++itemsReturned
1002+
itemsReturned += 1
10031003
}
10041004
if maxItems != nil && itemsReturned >= maxItems! {
10051005
return

test/1_stdlib/NSStringAPI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ NSStringAPIs.test("init(UTF8String:)") {
202202
var i = 0
203203
for b in s.utf8 {
204204
up[i] = b
205-
i++
205+
i += 1
206206
}
207207
up[i] = 0
208208
expectOptionalEqual(s, String(UTF8String: UnsafePointer(up)))

test/1_stdlib/Runtime.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import MirrorObjC
1717
var nsObjectCanaryCount = 0
1818
@objc class NSObjectCanary : NSObject {
1919
override init() {
20-
++nsObjectCanaryCount
20+
nsObjectCanaryCount += 1
2121
}
2222
deinit {
23-
--nsObjectCanaryCount
23+
nsObjectCanaryCount -= 1
2424
}
2525
}
2626

@@ -31,10 +31,10 @@ struct NSObjectCanaryStruct {
3131
var swiftObjectCanaryCount = 0
3232
class SwiftObjectCanary {
3333
init() {
34-
++swiftObjectCanaryCount
34+
swiftObjectCanaryCount += 1
3535
}
3636
deinit {
37-
--swiftObjectCanaryCount
37+
swiftObjectCanaryCount -= 1
3838
}
3939
}
4040

@@ -909,14 +909,14 @@ RuntimeFoundationWrappers.test("_stdlib_NSObject_isEqual/NoLeak") {
909909
var nsStringCanaryCount = 0
910910
@objc class NSStringCanary : NSString {
911911
override init() {
912-
++nsStringCanaryCount
912+
nsStringCanaryCount += 1
913913
super.init()
914914
}
915915
required init(coder: NSCoder) {
916916
fatalError("don't call this initializer")
917917
}
918918
deinit {
919-
--nsStringCanaryCount
919+
nsStringCanaryCount -= 1
920920
}
921921
@objc override var length: Int {
922922
return 0
@@ -2266,7 +2266,7 @@ func computeCountLeadingZeroes(x: Int64) -> Int64 {
22662266
var r: Int64 = 64
22672267
while x != 0 {
22682268
x >>= 1
2269-
r--
2269+
r -= 1
22702270
}
22712271
return r
22722272
}

test/1_stdlib/StringReallocation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func testReallocation() {
1515
story += " "
1616
story += s
1717
if lastBase != story._core._baseAddress {
18-
++reallocations
18+
reallocations += 1
1919

2020
// To avoid dumping a vast string here, just write the first
2121
// part of the story out each time there's a reallocation.

test/1_stdlib/Zip.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var i = 0
1010
var prefix = ""
1111
for p in zip(n, s) {
1212
print("\(prefix)\(p.0) => \(p.1)", terminator: "")
13-
++i
13+
i += 1
1414
prefix = ", "
1515
}
1616
print(" (\(i) items)")
@@ -20,7 +20,7 @@ i = 0
2020
prefix = ""
2121
for p in zip(s, n) {
2222
print("\(prefix)\(p.0) => \(p.1)", terminator: "")
23-
++i
23+
i += 1
2424
prefix = ", "
2525
}
2626
print(" (\(i) items)")

test/Constraints/nested_generics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct AnyStream<T : SequenceType> {
3434
func next() -> Element? {
3535
let result = (index, elements.next())
3636
if result.1 == nil { return .None }
37-
++index
37+
index += 1
3838
return (result.0, result.1!)
3939
}
4040
}

test/DebugInfo/inout2.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ struct Struct {
2626
func foo(inout x: Class) {
2727
// CHECK: !DILocalVariable(name: "x", arg: 1{{.*}} line: [[@LINE-1]]
2828
markUsed(x.ivar)
29-
x.ivar++ // Set breakpoint here
29+
x.ivar += 1 // Set breakpoint here
3030
}
3131

3232
func foo(inout x: Struct) {
3333
// CHECK: !DILocalVariable(name: "x", arg: 1{{.*}} line: [[@LINE-1]]
3434
markUsed(x.ivar)
35-
x.ivar++ // Set breakpoint here
35+
x.ivar += 1 // Set breakpoint here
3636
}
3737

3838
func main() {

test/Generics/algorithms.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func count<R : GeneratorType where R.Element : Eq>
4141
var result = 0
4242
for x in GeneratorSequence(range) {
4343
if x == value {
44-
++result
44+
result += 1
4545
}
4646
}
4747
return result
@@ -53,7 +53,7 @@ func countIf<
5353
var result = 0
5454
for x in GeneratorSequence(range) {
5555
if predicate(x) {
56-
++result
56+
result += 1
5757
}
5858
}
5959
return result

test/Generics/slice_test.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func find<T : Eq>(array: [T], value: T) -> Int {
102102
var idx = 0
103103
for elt in array {
104104
if (elt == value) { return idx }
105-
++idx
105+
idx += 1
106106
}
107107
return -1
108108
}
@@ -111,7 +111,7 @@ func findIf<T>(array: [T], fn: (T) -> Bool) -> Int {
111111
var idx = 0
112112
for elt in array {
113113
if (fn(elt)) { return idx }
114-
++idx
114+
idx += 1
115115
}
116116
return -1
117117
}

test/IDE/complete_value_expr.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,11 +1368,11 @@ func testResolveGenericParamsError1() {
13681368
class BuilderStyle<T> {
13691369
var count = 0
13701370
func addString(s: String) -> BuilderStyle<T> {
1371-
count++
1371+
count += 1
13721372
return self
13731373
}
13741374
func add(t: T) -> BuilderStyle<T> {
1375-
count++
1375+
count += 1
13761376
return self
13771377
}
13781378
func get() -> Int {

0 commit comments

Comments
 (0)