Skip to content

[gardening] Remove unnecessary breaks #24767

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

Merged
merged 1 commit into from
May 25, 2019
Merged
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
6 changes: 0 additions & 6 deletions stdlib/public/Darwin/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
precondition(range.lowerBound <= endIndex, "index \(range.lowerBound) is out of bounds of \(startIndex)..<\(endIndex)")
self = .large(LargeSlice(count: range.upperBound))
}
break
case .inline(var inline):
if inline.count < range.upperBound {
if InlineSlice.canStore(count: range.upperBound) {
Expand All @@ -1596,7 +1595,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
inline.resetBytes(in: range)
self = .inline(inline)
}
break
case .slice(var slice):
if InlineSlice.canStore(count: range.upperBound) {
self = .empty
Expand All @@ -1608,7 +1606,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
newSlice.resetBytes(in: range)
self = .large(newSlice)
}
break
case .large(var slice):
self = .empty
slice.resetBytes(in: range)
Expand All @@ -1630,7 +1627,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
} else {
self = .large(LargeSlice(UnsafeRawBufferPointer(start: bytes, count: cnt)))
}
break
case .inline(var inline):
let resultingCount = inline.count + cnt - (subrange.upperBound - subrange.lowerBound)
if resultingCount == 0 {
Expand All @@ -1647,7 +1643,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
slice.replaceSubrange(subrange, with: bytes, count: cnt)
self = .large(slice)
}
break
case .slice(var slice):
let resultingUpper = slice.endIndex + cnt - (subrange.upperBound - subrange.lowerBound)
if slice.startIndex == 0 && resultingUpper == 0 {
Expand Down Expand Up @@ -1820,7 +1815,6 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
return
case .inline(let inline):
inline.copyBytes(to: pointer, from: range)
break
case .slice(let slice):
slice.copyBytes(to: pointer, from: range)
case .large(let slice):
Expand Down
68 changes: 0 additions & 68 deletions stdlib/public/Darwin/Foundation/IndexPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,12 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
switch elements.count {
case 0:
self = .empty
break
case 1:
self = .single(elements[0])
break
case 2:
self = .pair(elements[0], elements[1])
break
default:
self = .array(elements)
break
}
}

Expand All @@ -74,16 +70,12 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
switch self {
case .empty:
self = .single(other)
break
case .single(let first):
self = .pair(first, other)
break
case .pair(let first, let second):
self = .array([first, second, other])
break
case .array(let indexes):
self = .array(indexes + [other])
break
}
}

Expand All @@ -96,63 +88,47 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
break
case .single(let rhsIndex):
self = .single(rhsIndex)
break
case .pair(let rhsFirst, let rhsSecond):
self = .pair(rhsFirst, rhsSecond)
break
case .array(let rhsIndexes):
self = .array(rhsIndexes)
break
}
break
case .single(let lhsIndex):
switch other {
case .empty:
// DO NOTHING
break
case .single(let rhsIndex):
self = .pair(lhsIndex, rhsIndex)
break
case .pair(let rhsFirst, let rhsSecond):
self = .array([lhsIndex, rhsFirst, rhsSecond])
break
case .array(let rhsIndexes):
self = .array([lhsIndex] + rhsIndexes)
break
}
break
case .pair(let lhsFirst, let lhsSecond):
switch other {
case .empty:
// DO NOTHING
break
case .single(let rhsIndex):
self = .array([lhsFirst, lhsSecond, rhsIndex])
break
case .pair(let rhsFirst, let rhsSecond):
self = .array([lhsFirst, lhsSecond, rhsFirst, rhsSecond])
break
case .array(let rhsIndexes):
self = .array([lhsFirst, lhsSecond] + rhsIndexes)
break
}
break
case .array(let lhsIndexes):
switch other {
case .empty:
// DO NOTHING
break
case .single(let rhsIndex):
self = .array(lhsIndexes + [rhsIndex])
break
case .pair(let rhsFirst, let rhsSecond):
self = .array(lhsIndexes + [rhsFirst, rhsSecond])
break
case .array(let rhsIndexes):
self = .array(lhsIndexes + rhsIndexes)
break
}
break
}
}

Expand All @@ -165,41 +141,31 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
break
case 1:
self = .single(other[0])
break
case 2:
self = .pair(other[0], other[1])
break
default:
self = .array(other)
break
}
break
case .single(let first):
switch other.count {
case 0:
// DO NOTHING
break
case 1:
self = .pair(first, other[0])
break
default:
self = .array([first] + other)
break
}
break
case .pair(let first, let second):
switch other.count {
case 0:
// DO NOTHING
break
default:
self = .array([first, second] + other)
break
}
break
case .array(let indexes):
self = .array(indexes + other)
break
}
}

Expand All @@ -208,7 +174,6 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
switch self {
case .empty:
fatalError("Index \(index) out of bounds of count 0")
break
case .single(let first):
precondition(index == 0, "Index \(index) out of bounds of count 1")
return first
Expand All @@ -223,24 +188,20 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
switch self {
case .empty:
fatalError("Index \(index) out of bounds of count 0")
break
case .single(_):
precondition(index == 0, "Index \(index) out of bounds of count 1")
self = .single(newValue)
break
case .pair(let first, let second):
precondition(index >= 0 && index < 2, "Index \(index) out of bounds of count 2")
if index == 0 {
self = .pair(newValue, second)
} else {
self = .pair(first, newValue)
}
break
case .array(let indexes_):
var indexes = indexes_
indexes[index] = newValue
self = .array(indexes)
break
}
}
}
Expand All @@ -266,7 +227,6 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
fatalError("Range \(range) is out of bounds of count 1")
}
case .pair(let first, let second):

switch (range.lowerBound, range.upperBound) {
case (0, 0):
fallthrough
Expand Down Expand Up @@ -302,7 +262,6 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
case .empty:
precondition(range.lowerBound == 0 && range.upperBound == 0, "Range \(range) is out of bounds of count 0")
self = newValue
break
case .single(let index):
switch (range.lowerBound, range.upperBound, newValue) {
case (0, 0, .empty):
Expand All @@ -311,13 +270,10 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
break
case (0, 0, .single(let other)):
self = .pair(other, index)
break
case (0, 0, .pair(let first, let second)):
self = .array([first, second, index])
break
case (0, 0, .array(let other)):
self = .array(other + [index])
break
case (0, 1, .empty):
fallthrough
case (0, 1, .single):
Expand All @@ -328,13 +284,10 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
self = newValue
case (1, 1, .single(let other)):
self = .pair(index, other)
break
case (1, 1, .pair(let first, let second)):
self = .array([index, first, second])
break
case (1, 1, .array(let other)):
self = .array([index] + other)
break
default:
fatalError("Range \(range) is out of bounds of count 1")
}
Expand All @@ -346,63 +299,46 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
break
case .single(let other):
self = .array([other, first, second])
break
case .pair(let otherFirst, let otherSecond):
self = .array([otherFirst, otherSecond, first, second])
break
case .array(let other):
self = .array(other + [first, second])
break
}
break
case (0, 1):
switch newValue {
case .empty:
self = .single(second)
break
case .single(let other):
self = .pair(other, second)
break
case .pair(let otherFirst, let otherSecond):
self = .array([otherFirst, otherSecond, second])
break
case .array(let other):
self = .array(other + [second])
break
}
break
case (0, 2):
self = newValue
break
case (1, 2):
switch newValue {
case .empty:
self = .single(first)
break
case .single(let other):
self = .pair(first, other)
break
case .pair(let otherFirst, let otherSecond):
self = .array([first, otherFirst, otherSecond])
break
case .array(let other):
self = .array([first] + other)
}
break
case (2, 2):
switch newValue {
case .empty:
break
case .single(let other):
self = .array([first, second, other])
break
case .pair(let otherFirst, let otherSecond):
self = .array([first, second, otherFirst, otherSecond])
break
case .array(let other):
self = .array([first, second] + other)
}
break
default:
fatalError("Range \(range) is out of bounds of count 2")
}
Expand All @@ -414,17 +350,13 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
break
case .single(let index):
newIndexes.insert(index, at: range.lowerBound)
break
case .pair(let first, let second):
newIndexes.insert(first, at: range.lowerBound)
newIndexes.insert(second, at: range.lowerBound + 1)
break
case .array(let other):
newIndexes.insert(contentsOf: other, at: range.lowerBound)
break
}
self = Storage(newIndexes)
break
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions test/stdlib/TestJSONEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1259,8 +1259,6 @@ func expectEqualPaths(_ lhs: [CodingKey], _ rhs: [CodingKey], _ prefix: String)
expectUnreachable("\(prefix) CodingKey.intValue mismatch: \(type(of: key1))(\(i1)) != \(type(of: key2))(\(i2))")
return
}

break
}

expectEqual(key1.stringValue, key2.stringValue, "\(prefix) CodingKey.stringValue mismatch: \(type(of: key1))('\(key1.stringValue)') != \(type(of: key2))('\(key2.stringValue)')")
Expand Down