Skip to content

Commit 3946624

Browse files
committed
Gets rid of for-loop deprecation compiler warnings in stdlib/public/core
1 parent faba6e5 commit 3946624

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

stdlib/public/core/CString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public func _persistCString(s: UnsafePointer<CChar>) -> [CChar]? {
6060
}
6161
let length = Int(_swift_stdlib_strlen(s))
6262
var result = [CChar](count: length + 1, repeatedValue: 0)
63-
for var i = 0; i < length; ++i {
63+
for i in 0..<length {
6464
// FIXME: this will not compile on platforms where 'CChar' is unsigned.
6565
result[i] = s[i]
6666
}

stdlib/public/core/Character.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public struct Character :
120120
@warn_unused_result
121121
static func _smallSize(value: UInt64) -> Int {
122122
var mask: UInt64 = 0xFF
123-
for var i = 0; i < 8; ++i {
123+
for i in 0..<8 {
124124
if (value & mask) == mask {
125125
return i
126126
}

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
21132113
var description: String {
21142114
var result = ""
21152115
#if INTERNAL_CHECKS_ENABLED
2116-
for var i = 0; i != capacity; ++i {
2116+
for i in 0..<capacity {
21172117
if isInitializedEntry(i) {
21182118
let key = keyAt(i)
21192119
result += "bucket \(i), ideal bucket = \(_bucket(key)), key = \(key)\n"
@@ -3248,19 +3248,19 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
32483248

32493249
// Find the last bucket in the contiguous chain
32503250
var lastInChain = hole
3251-
for var b = nativeStorage._next(lastInChain);
3252-
nativeStorage.isInitializedEntry(b);
3253-
b = nativeStorage._next(b) {
3251+
var b = nativeStorage._next(lastInChain);
3252+
while nativeStorage.isInitializedEntry(b) {
32543253
lastInChain = b
3254+
b = nativeStorage._next(b)
32553255
}
32563256

32573257
// Relocate out-of-place elements in the chain, repeating until
32583258
// none are found.
32593259
while hole != lastInChain {
32603260
// Walk backwards from the end of the chain looking for
32613261
// something out-of-place.
3262-
var b: Int
3263-
for b = lastInChain; b != hole; b = nativeStorage._prev(b) {
3262+
var b = lastInChain
3263+
while b != hole {
32643264
let idealBucket = nativeStorage._bucket(nativeStorage.keyAt(b))
32653265

32663266
// Does this element belong between start and hole? We need
@@ -3271,6 +3271,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
32713271
if start <= hole ? (c0 && c1) : (c0 || c1) {
32723272
break // Found it
32733273
}
3274+
b = nativeStorage._prev(b)
32743275
}
32753276

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

stdlib/public/core/Prespecialized.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ struct _Prespecialize {
2929
a[0] = a[j]
3030
}
3131

32-
for var i1 = 0; i1 < a.count; ++i1 {
33-
for var i2 = 0; i2 < a.count; ++i2 {
32+
for i1 in 0..<a.count {
33+
for i2 in 0..<a.count {
3434
a[i1] = a[i2]
3535
}
3636
}

stdlib/public/core/StringCharacterView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ extension String.CharacterView : CollectionType {
145145
unicodeScalars[start].value)
146146
start._successorInPlace()
147147

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

163164
return start._position - startIndexUTF16

stdlib/public/core/Unicode.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,8 @@ public func transcode<
705705

706706
var inputDecoder = inputEncoding.init()
707707
var hadError = false
708-
for var scalar = inputDecoder.decode(&input);
709-
!scalar.isEmptyInput();
710-
scalar = inputDecoder.decode(&input) {
708+
var scalar = inputDecoder.decode(&input)
709+
while !scalar.isEmptyInput() {
711710
switch scalar {
712711
case .Result(let us):
713712
OutputEncoding.encode(us, output: output)
@@ -721,6 +720,7 @@ public func transcode<
721720
hadError = true
722721
}
723722
}
723+
scalar = inputDecoder.decode(&input)
724724
}
725725
return hadError
726726
}

stdlib/public/core/UnsafePointer.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ ${comment}
210210
_debugPrecondition(
211211
source < self || source >= self + count,
212212
"${Self}.assignBackwardFrom non-preceding overlapping range; use assignFrom instead")
213-
for var i = count; --i >= 0; {
213+
for i in (0..<count).reverse() {
214214
self[i] = source[i]
215215
}
216216
}

0 commit comments

Comments
 (0)