mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] Change C-style for loop to Swift-style for-in loop
This commit is contained in:
@@ -713,15 +713,18 @@ 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() {
|
||||
var i = lhsNative.startIndex
|
||||
while i != endIndex {
|
||||
let key = lhsNative.assertingGet(i)
|
||||
let bridgedKey: AnyObject = _bridgeToObjectiveCUnconditional(key)
|
||||
let optRhsValue: AnyObject? = rhsCocoa.maybeGet(bridgedKey)
|
||||
if let rhsValue = optRhsValue {
|
||||
if key == _forceBridgeFromObjectiveC(rhsValue, Element.self) {
|
||||
i = i.successor()
|
||||
continue
|
||||
}
|
||||
}
|
||||
i = i.successor()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -1230,16 +1233,18 @@ 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
|
||||
}
|
||||
}
|
||||
index._successorInPlace()
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -2113,7 +2118,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
|
||||
var description: String {
|
||||
var result = ""
|
||||
#if INTERNAL_CHECKS_ENABLED
|
||||
for var i = 0; i != capacity; i += 1 {
|
||||
for i in 0..<capacity {
|
||||
if isInitializedEntry(i) {
|
||||
let key = keyAt(i)
|
||||
result += "bucket \(i), ideal bucket = \(_bucket(key)), key = \(key)\n"
|
||||
@@ -2601,7 +2606,7 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
||||
let bridged = _createBridgedNativeStorage(nativeStorage.capacity)
|
||||
|
||||
// Bridge everything.
|
||||
for var i = 0; i < nativeStorage.capacity; i += 1 {
|
||||
for i in 0..<nativeStorage.capacity {
|
||||
if nativeStorage.isInitializedEntry(i) {
|
||||
let key = _bridgeToObjectiveCUnconditional(nativeStorage.keyAt(i))
|
||||
%if Self == 'Set':
|
||||
@@ -3248,10 +3253,10 @@ 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) {
|
||||
var b = nativeStorage._next(lastInChain)
|
||||
while nativeStorage.isInitializedEntry(b) {
|
||||
lastInChain = b
|
||||
b = nativeStorage._next(b)
|
||||
}
|
||||
|
||||
// Relocate out-of-place elements in the chain, repeating until
|
||||
@@ -3259,8 +3264,8 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
||||
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) {
|
||||
var b = lastInChain
|
||||
while b != hole {
|
||||
let idealBucket = nativeStorage._bucket(nativeStorage.keyAt(b))
|
||||
|
||||
// Does this element belong between start and hole? We need
|
||||
@@ -3271,6 +3276,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
||||
if start <= hole ? (c0 && c1) : (c0 || c1) {
|
||||
break // Found it
|
||||
}
|
||||
b = nativeStorage._prev(b)
|
||||
}
|
||||
|
||||
if b == hole { // No out-of-place elements found; we're done adjusting
|
||||
@@ -3409,7 +3415,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorageType {
|
||||
nativeStorage = native
|
||||
}
|
||||
|
||||
for var b = 0; b != nativeStorage.capacity; b += 1 {
|
||||
for b in 0..<nativeStorage.capacity {
|
||||
if nativeStorage.isInitializedEntry(b) {
|
||||
nativeStorage.destroyEntryAt(b)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user