Skip to content

Purge warnings generated from C-style for-loops #679

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion stdlib/public/core/CString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public func _persistCString(s: UnsafePointer<CChar>) -> [CChar]? {
}
let length = Int(_swift_stdlib_strlen(s))
var result = [CChar](count: length + 1, repeatedValue: 0)
for var i = 0; i < length; ++i {
for i in 0..<length {
// FIXME: this will not compile on platforms where 'CChar' is unsigned.
result[i] = s[i]
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Character.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public struct Character :
@warn_unused_result
static func _smallSize(value: UInt64) -> Int {
var mask: UInt64 = 0xFF
for var i = 0; i < 8; ++i {
for i in 0..<8 {
if (value & mask) == mask {
return i
}
Expand Down
37 changes: 20 additions & 17 deletions stdlib/public/core/HashedCollections.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -730,12 +730,14 @@ public func == <Element : Hashable>(lhs: Set<Element>, rhs: Set<Element>) -> Boo
}

let endIndex = lhsNative.endIndex
for var i = lhsNative.startIndex; i != endIndex; i = i.successor() {
let key = lhsNative.assertingGet(i)
var index = lhsNative.startIndex
while index != endIndex {
let key = lhsNative.assertingGet(index)
let bridgedKey: AnyObject = _bridgeToObjectiveCUnconditional(key)
let optRhsValue: AnyObject? = rhsCocoa.maybeGet(bridgedKey)
if let rhsValue = optRhsValue {
if key == _forceBridgeFromObjectiveC(rhsValue, Element.self) {
index = index.successor()
continue
}
}
Expand Down Expand Up @@ -1247,13 +1249,14 @@ public func == <Key : Equatable, Value : Equatable>(
}

let endIndex = lhsNative.endIndex
for var index = lhsNative.startIndex; index != endIndex;
index._successorInPlace() {
var index = lhsNative.startIndex
while index != endIndex {
let (key, value) = lhsNative.assertingGet(index)
let optRhsValue: AnyObject? =
rhsCocoa.maybeGet(_bridgeToObjectiveCUnconditional(key))
if let rhsValue = optRhsValue {
if value == _forceBridgeFromObjectiveC(rhsValue, Value.self) {
index._successorInPlace()
continue
}
}
Expand Down Expand Up @@ -2130,7 +2133,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
var description: String {
var result = ""
#if INTERNAL_CHECKS_ENABLED
for var i = 0; i != capacity; ++i {
for i in 0..<capacity {
if isInitializedEntry(i) {
let key = keyAt(i)
result += "bucket \(i), ideal bucket = \(_bucket(key)), key = \(key)\n"
Expand Down Expand Up @@ -2618,7 +2621,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
let bridged = _createBridgedNativeStorage(nativeStorage.capacity)

// Bridge everything.
for var i = 0; i < nativeStorage.capacity; ++i {
for i in 0..<nativeStorage.capacity {
if nativeStorage.isInitializedEntry(i) {
let key = _bridgeToObjectiveCUnconditional(nativeStorage.keyAt(i))
%if Self == 'Set':
Expand Down Expand Up @@ -3265,20 +3268,19 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {

// Find the last bucket in the contiguous chain
var lastInChain = hole
for var b = nativeStorage._next(lastInChain);
nativeStorage.isInitializedEntry(b);
b = nativeStorage._next(b) {
lastInChain = b
var bucket = nativeStorage._next(lastInChain)
while nativeStorage.isInitializedEntry(bucket) {
lastInChain = bucket
bucket = nativeStorage._next(bucket)
}

// Relocate out-of-place elements in the chain, repeating until
// none are found.
while hole != lastInChain {
// Walk backwards from the end of the chain looking for
// something out-of-place.
var b: Int
for b = lastInChain; b != hole; b = nativeStorage._prev(b) {
let idealBucket = nativeStorage._bucket(nativeStorage.keyAt(b))
var bucket: Int = lastInChain
while bucket != hole {
let idealBucket = nativeStorage._bucket(nativeStorage.keyAt(bucket))

// Does this element belong between start and hole? We need
// two separate tests depending on whether [start,hole] wraps
Expand All @@ -3288,15 +3290,16 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
if start <= hole ? (c0 && c1) : (c0 || c1) {
break // Found it
}
bucket = nativeStorage._prev(bucket)
}

if b == hole { // No out-of-place elements found; we're done adjusting
if bucket == hole { // No out-of-place elements found; we're done adjusting
break
}

// Move the found element into the hole
nativeStorage.moveInitializeFrom(nativeStorage, at: b, toEntryAt: hole)
hole = b
nativeStorage.moveInitializeFrom(nativeStorage, at: bucket, toEntryAt: hole)
hole = bucket
}
}

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Prespecialized.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct _Prespecialize {
a[0] = a[j]
}

for var i1 = 0; i1 < a.count; ++i1 {
for var i2 = 0; i2 < a.count; ++i2 {
for i1 in 0..<a.count {
for i2 in 0..<a.count {
a[i1] = a[i2]
}
}
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/core/StringCharacterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ extension String.CharacterView : CollectionType {
unicodeScalars[start].value)
start._successorInPlace()

for ; start != end; start._successorInPlace() {
while start != end {
// FIXME(performance): consider removing this "fast path". A branch
// that is hard to predict could be worse for performance than a few
// loads from cache to fetch the property 'gcb1'.
Expand All @@ -158,6 +158,7 @@ extension String.CharacterView : CollectionType {
break
}
gcb0 = gcb1
start._successorInPlace()
}

return start._position - startIndexUTF16
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/core/Unicode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,8 @@ public func transcode<

var inputDecoder = inputEncoding.init()
var hadError = false
for var scalar = inputDecoder.decode(&input);
!scalar.isEmptyInput();
scalar = inputDecoder.decode(&input) {
var scalar = inputDecoder.decode(&input);
while !scalar.isEmptyInput() {
switch scalar {
case .Result(let us):
OutputEncoding.encode(us, output: output)
Expand All @@ -721,6 +720,7 @@ public func transcode<
hadError = true
}
}
scalar = inputDecoder.decode(&input)
}
return hadError
}
Expand Down
4 changes: 3 additions & 1 deletion stdlib/public/core/UnsafePointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ ${comment}
_debugPrecondition(
source < self || source >= self + count,
"${Self}.assignBackwardFrom non-preceding overlapping range; use assignFrom instead")
for var i = count; --i >= 0; {
var i = count
while i >= 0 {
i -= 1
self[i] = source[i]
}
}
Expand Down