Skip to content

Commit 44f0e93

Browse files
authored
Merge pull request swiftlang#25067 from ikesyo/avoid-fallthrough-where-appropriate
[gardening] Avoid fallthrough where appropriate (for readability/understandability)
2 parents 2019a97 + c1bb945 commit 44f0e93

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

stdlib/public/Darwin/Foundation/IndexPath.swift

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
218218
}
219219
case .single(let index):
220220
switch (range.lowerBound, range.upperBound) {
221-
case (0, 0): fallthrough
222-
case (1, 1):
221+
case (0, 0),
222+
(1, 1):
223223
return .empty
224224
case (0, 1):
225225
return .single(index)
@@ -228,11 +228,9 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
228228
}
229229
case .pair(let first, let second):
230230
switch (range.lowerBound, range.upperBound) {
231-
case (0, 0):
232-
fallthrough
233-
case (1, 1):
234-
fallthrough
235-
case (2, 2):
231+
case (0, 0),
232+
(1, 1),
233+
(2, 2):
236234
return .empty
237235
case (0, 1):
238236
return .single(first)
@@ -264,23 +262,19 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
264262
self = newValue
265263
case .single(let index):
266264
switch (range.lowerBound, range.upperBound, newValue) {
267-
case (0, 0, .empty):
268-
fallthrough
269-
case (1, 1, .empty):
265+
case (0, 0, .empty),
266+
(1, 1, .empty):
270267
break
271268
case (0, 0, .single(let other)):
272269
self = .pair(other, index)
273270
case (0, 0, .pair(let first, let second)):
274271
self = .array([first, second, index])
275272
case (0, 0, .array(let other)):
276273
self = .array(other + [index])
277-
case (0, 1, .empty):
278-
fallthrough
279-
case (0, 1, .single):
280-
fallthrough
281-
case (0, 1, .pair):
282-
fallthrough
283-
case (0, 1, .array):
274+
case (0, 1, .empty),
275+
(0, 1, .single),
276+
(0, 1, .pair),
277+
(0, 1, .array):
284278
self = newValue
285279
case (1, 1, .single(let other)):
286280
self = .pair(index, other)

stdlib/public/core/StringStorage.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ extension _AbstractStringStorage {
7272
_ outputPtr: UnsafeMutablePointer<UInt8>, _ maxLength: Int, _ encoding: UInt
7373
) -> Int8 {
7474
switch (encoding, isASCII) {
75-
case (_cocoaASCIIEncoding, true):
76-
fallthrough
77-
case (_cocoaUTF8Encoding, _):
75+
case (_cocoaASCIIEncoding, true),
76+
(_cocoaUTF8Encoding, _):
7877
guard maxLength >= count + 1 else { return 0 }
7978
outputPtr.initialize(from: start, count: count)
8079
outputPtr[count] = 0
@@ -88,9 +87,8 @@ extension _AbstractStringStorage {
8887
@_effects(readonly)
8988
internal func _cString(encoding: UInt) -> UnsafePointer<UInt8>? {
9089
switch (encoding, isASCII) {
91-
case (_cocoaASCIIEncoding, true):
92-
fallthrough
93-
case (_cocoaUTF8Encoding, _):
90+
case (_cocoaASCIIEncoding, true),
91+
(_cocoaUTF8Encoding, _):
9492
return start
9593
default:
9694
return _cocoaCStringUsingEncodingTrampoline(self, encoding)

0 commit comments

Comments
 (0)