Skip to content

Commit 4b8fff4

Browse files
committed
Merge pull request #270 from hamin/cleaning-up-cstyle-loops
A small step towards removing C-style loops
2 parents 18e16ed + 0d00148 commit 4b8fff4

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
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/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
}

utils/benchmark/Phonebook/Phonebook.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ for first in words {
5656

5757
func benchStringSort() {
5858
let start = __mach_absolute_time__()
59-
for (var i = 0; i < 100; i++) {
60-
var t = Names;
59+
for i in 0..<100 {
60+
var t = Names
6161
sort(&t)
6262
}
6363
let delta = __mach_absolute_time__() - start

utils/benchmark/RC4/RC4.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func benchRC4_internal(messageLen : Int, iterations : Int) {
5858
var LongData : UInt8[] = new UInt8[messageLen]
5959

6060
// Generate a long message.
61-
for (var i = 0; i < messageLen; i++) {
61+
for i in 0..<messageLen {
6262
LongData[i] = SecretData[i % SecretData.count]
6363
}
6464

@@ -67,7 +67,7 @@ func benchRC4_internal(messageLen : Int, iterations : Int) {
6767

6868
let start = __mach_absolute_time__()
6969

70-
for (var i = 0; i < iterations; i++) {
70+
for i in 0..<iterations {
7171
Enc.encrypt(&LongData)
7272
}
7373

validation-test/stdlib/OpenCLSDKOverlay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ tests.test("clSetKernelArgsListAPPLE") {
9797
//
9898
var i = 0
9999
var count = DATA_SIZE
100-
for i = 0; i < count; i++ {
100+
for i in 0..<count {
101101
data[i] = Float(rand()) / Float(RAND_MAX)
102102
}
103103

0 commit comments

Comments
 (0)