Skip to content

replace singular statement ++/-- with += 1/-= 1 for integer variables #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions stdlib/private/StdlibUnittest/RaceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ struct _RaceTestAggregatedEvaluations : CustomStringConvertible {
mutating func addEvaluation(evaluation: RaceTestObservationEvaluation) {
switch evaluation {
case .Pass:
++passCount
passCount += 1

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

case .Failure:
++failureCount
failureCount += 1

case .FailureInteresting(let s):
if failureInterestingCount[s] == nil {
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 @@ -49,7 +49,7 @@ public struct _FDInputStream {
_buffer.reserveCapacity(minFree - bufferFree)
while bufferFree < minFree {
_buffer.append(0)
++bufferFree
bufferFree += 1
}
}
let readResult: __swift_ssize_t = _buffer.withUnsafeMutableBufferPointer {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ final public class NSFastGenerator : GeneratorType {
if count == 0 { return .None }
}
let next : AnyObject = state[0].itemsPtr[n]!
++n
n += 1
return next
}

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/SDK/Foundation/NSStringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func _countFormatSpecifiers(a: String) -> Int {
lastChar = notPercentUTF16
}
else {
++count
count += 1
lastChar = c
}
} else {
Expand Down Expand Up @@ -141,7 +141,7 @@ extension String {
var p = NSString.availableStringEncodings()
while p.memory != 0 {
result.append(p.memory)
++p
p += 1
}
return result
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ extension _ArrayBuffer {
var result = target
for _ in subRange {
result.initialize(result.memory)
++result
result += 1
}
return result
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ContiguousArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
mutating func addWithExistingCapacity(element: Element) {
_sanityCheck(remainingCapacity > 0,
"_UnsafePartiallyInitializedContiguousArrayBuffer has no more capacity")
remainingCapacity--
remainingCapacity -= 1

(p++).initialize(element)
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Reflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func _dumpWithMirror<TargetStream : OutputStreamType>(
inout _ targetStream: TargetStream
) {
if maxItemCounter <= 0 { return }
--maxItemCounter
maxItemCounter -= 1

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

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ internal class _DropFirstSequence<Base : GeneratorType>
dropped = limit
return nil
}
++dropped
dropped += 1
}
return generator.next()
}
Expand Down Expand Up @@ -270,7 +270,7 @@ internal class _PrefixSequence<Base : GeneratorType> : SequenceType, GeneratorTy

internal func next() -> Base.Element? {
if taken >= maxLength { return nil }
++taken
taken += 1

if let next = generator.next() {
return next
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/StaticString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public struct StaticString
var i = 0
let sink: (UInt8) -> Void = {
buffer = buffer | (UInt64($0) << (UInt64(i) * 8))
++i
i += 1
}
UTF8.encode(unicodeScalar, output: sink)
return body(UnsafeBufferPointer(
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/StringUnicodeScalarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extension String {
let codeUnit = _core[--i]
if _slowPath((codeUnit >> 10) == 0b1101_11) {
if i != 0 && (_core[i - 1] >> 10) == 0b1101_10 {
--i
i -= 1
}
}
return Index(i, _core)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/VarArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ final public class VaListBuilder {
+ (sseRegistersUsed * _x86_64SSERegisterWords)
for w in encoded {
storage[startIndex] = w
++startIndex
startIndex += 1
}
++sseRegistersUsed
sseRegistersUsed += 1
}
else if encoded.count == 1 && gpRegistersUsed < _x86_64CountGPRegisters {
storage[gpRegistersUsed++] = encoded[0]
Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/Dispatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ DispatchAPI.test("OS_OBJECT support") {
DispatchAPI.test("dispatch_block_t conversions") {
var counter = 0
let closure = { () -> Void in
counter++
counter += 1
}

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

let block = dispatch_block_create(dispatch_block_flags_t(0)) {
counter++
counter += 1
}
block()
expectEqual(1, counter)
Expand Down
14 changes: 7 additions & 7 deletions test/1_stdlib/ErrorHandling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ ErrorHandlingTests.test("ErrorHandling/forEach") {
var loopCount = 0
do {
try [1, 2, 3].forEach {
++loopCount
loopCount += 1
if $0 == 2 {
throw SillyError.JazzHands
}
Expand All @@ -143,7 +143,7 @@ ErrorHandlingTests.test("ErrorHandling/Optional flatMap") {
var loopCount = 0
do {
let _: [Int] = try [1, 2, 3].flatMap {
++loopCount
loopCount += 1
if $0 == 2 {
throw SillyError.JazzHands
}
Expand All @@ -159,7 +159,7 @@ ErrorHandlingTests.test("ErrorHandling/Array flatMap") {
var loopCount = 0
do {
let _: [Int] = try [1, 2, 3].flatMap {(x) -> [Int] in
++loopCount
loopCount += 1
if x == 2 {
throw SillyError.JazzHands
}
Expand Down Expand Up @@ -235,7 +235,7 @@ ErrorHandlingTests.test("ErrorHandling/reduce") {
let x: Int = try [1, 2, 3, 4, 5].reduce(0, combine: {
(x: Int, y: Int) -> Int
in
++loopCount
loopCount += 1
var total = x + y
if total > 5 {
throw SillyError.JazzHands
Expand Down Expand Up @@ -287,7 +287,7 @@ ErrorHandlingTests.test("ErrorHandling/Sequence map") {
if loopCount == throwAtCount {
throw SillyError.JazzHands
}
++loopCount
loopCount += 1
return Noisy()
}
expectEqual(NoisyCount, initialCount + 3)
Expand All @@ -308,7 +308,7 @@ ErrorHandlingTests.test("ErrorHandling/Sequence filter") {
if loopCount == throwAtCount {
throw SillyError.JazzHands
}
++loopCount
loopCount += 1
return condition
}
expectEqual(NoisyCount, initialCount + sequence.count)
Expand All @@ -329,7 +329,7 @@ ErrorHandlingTests.test("ErrorHandling/Collection map") {
if loopCount == throwAtCount {
throw SillyError.JazzHands
}
++loopCount
loopCount += 1
return Noisy()
}
expectEqual(NoisyCount, initialCount + 3)
Expand Down
10 changes: 5 additions & 5 deletions test/1_stdlib/Inputs/DictionaryKeyValueTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,15 @@ struct TestBridgedValueTy : CustomStringConvertible, _ObjectiveCBridgeable {
}

func _bridgeToObjectiveC() -> TestObjCValueTy {
TestBridgedValueTy.bridgeOperations++
TestBridgedValueTy.bridgeOperations += 1
return TestObjCValueTy(value)
}

static func _forceBridgeFromObjectiveC(
x: TestObjCValueTy,
inout result: TestBridgedValueTy?
) {
TestBridgedValueTy.bridgeOperations++
TestBridgedValueTy.bridgeOperations += 1
result = TestBridgedValueTy(x.value)
}

Expand Down Expand Up @@ -637,7 +637,7 @@ func slurpFastEnumerationFromSwift(
for i in 0..<returnedCount {
let value: AnyObject = state.itemsPtr[i]!
sink(value)
++itemsReturned
itemsReturned += 1
}
if maxItems != nil && itemsReturned >= maxItems! {
return
Expand Down Expand Up @@ -681,7 +681,7 @@ func slurpFastEnumerationFromSwift(
let value: AnyObject = d.objectForKey(key)!
let kv = (key, value)
sink(kv)
++itemsReturned
itemsReturned += 1
}
if maxItems != nil && itemsReturned >= maxItems! {
return
Expand Down Expand Up @@ -999,7 +999,7 @@ func slurpFastEnumerationFromSwift(
for i in 0..<returnedCount {
let value: AnyObject = state.itemsPtr[i]!
sink(value)
++itemsReturned
itemsReturned += 1
}
if maxItems != nil && itemsReturned >= maxItems! {
return
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/NSStringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ NSStringAPIs.test("init(UTF8String:)") {
var i = 0
for b in s.utf8 {
up[i] = b
i++
i += 1
}
up[i] = 0
expectOptionalEqual(s, String(UTF8String: UnsafePointer(up)))
Expand Down
14 changes: 7 additions & 7 deletions test/1_stdlib/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import MirrorObjC
var nsObjectCanaryCount = 0
@objc class NSObjectCanary : NSObject {
override init() {
++nsObjectCanaryCount
nsObjectCanaryCount += 1
}
deinit {
--nsObjectCanaryCount
nsObjectCanaryCount -= 1
}
}

Expand All @@ -31,10 +31,10 @@ struct NSObjectCanaryStruct {
var swiftObjectCanaryCount = 0
class SwiftObjectCanary {
init() {
++swiftObjectCanaryCount
swiftObjectCanaryCount += 1
}
deinit {
--swiftObjectCanaryCount
swiftObjectCanaryCount -= 1
}
}

Expand Down Expand Up @@ -909,14 +909,14 @@ RuntimeFoundationWrappers.test("_stdlib_NSObject_isEqual/NoLeak") {
var nsStringCanaryCount = 0
@objc class NSStringCanary : NSString {
override init() {
++nsStringCanaryCount
nsStringCanaryCount += 1
super.init()
}
required init(coder: NSCoder) {
fatalError("don't call this initializer")
}
deinit {
--nsStringCanaryCount
nsStringCanaryCount -= 1
}
@objc override var length: Int {
return 0
Expand Down Expand Up @@ -2266,7 +2266,7 @@ func computeCountLeadingZeroes(x: Int64) -> Int64 {
var r: Int64 = 64
while x != 0 {
x >>= 1
r--
r -= 1
}
return r
}
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/StringReallocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func testReallocation() {
story += " "
story += s
if lastBase != story._core._baseAddress {
++reallocations
reallocations += 1

// To avoid dumping a vast string here, just write the first
// part of the story out each time there's a reallocation.
Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var i = 0
var prefix = ""
for p in zip(n, s) {
print("\(prefix)\(p.0) => \(p.1)", terminator: "")
++i
i += 1
prefix = ", "
}
print(" (\(i) items)")
Expand All @@ -20,7 +20,7 @@ i = 0
prefix = ""
for p in zip(s, n) {
print("\(prefix)\(p.0) => \(p.1)", terminator: "")
++i
i += 1
prefix = ", "
}
print(" (\(i) items)")
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/nested_generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct AnyStream<T : SequenceType> {
func next() -> Element? {
let result = (index, elements.next())
if result.1 == nil { return .None }
++index
index += 1
return (result.0, result.1!)
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/DebugInfo/inout2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ struct Struct {
func foo(inout x: Class) {
// CHECK: !DILocalVariable(name: "x", arg: 1{{.*}} line: [[@LINE-1]]
markUsed(x.ivar)
x.ivar++ // Set breakpoint here
x.ivar += 1 // Set breakpoint here
}

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

func main() {
Expand Down
4 changes: 2 additions & 2 deletions test/Generics/algorithms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func count<R : GeneratorType where R.Element : Eq>
var result = 0
for x in GeneratorSequence(range) {
if x == value {
++result
result += 1
}
}
return result
Expand All @@ -53,7 +53,7 @@ func countIf<
var result = 0
for x in GeneratorSequence(range) {
if predicate(x) {
++result
result += 1
}
}
return result
Expand Down
Loading