Skip to content

[gardening] Remove unnecessary breaks #2257

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 13, 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 Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,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 @@ -1629,7 +1628,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 @@ -1641,7 +1639,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 @@ -1663,7 +1660,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 @@ -1680,7 +1676,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 @@ -1853,7 +1848,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
69 changes: 0 additions & 69 deletions Foundation/IndexPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,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 @@ -87,16 +83,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 @@ -109,63 +101,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 @@ -178,41 +154,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 @@ -221,7 +187,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 @@ -236,24 +201,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 @@ -278,9 +239,7 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
default:
fatalError("range \(range) is out of bounds of count 1")
}
return self
case .pair(let first, let second):

switch (range.lowerBound, range.upperBound) {
case (0, 0):
fallthrough
Expand Down Expand Up @@ -316,7 +275,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 @@ -325,13 +283,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 @@ -342,13 +297,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 @@ -360,63 +312,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 @@ -428,17 +363,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
7 changes: 0 additions & 7 deletions Foundation/NSNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1065,27 +1065,21 @@ open class NSNumber : NSValue {
switch type {
case kCFNumberSInt8Type:
valuePtr.assumingMemoryBound(to: Int8.self).pointee = int8Value
break
case kCFNumberSInt16Type:
valuePtr.assumingMemoryBound(to: Int16.self).pointee = int16Value
break
case kCFNumberSInt32Type:
valuePtr.assumingMemoryBound(to: Int32.self).pointee = int32Value
break
case kCFNumberSInt64Type:
valuePtr.assumingMemoryBound(to: Int64.self).pointee = int64Value
break
case kCFNumberSInt128Type:
struct CFSInt128Struct {
var high: Int64
var low: UInt64
}
let val = int64Value
valuePtr.assumingMemoryBound(to: CFSInt128Struct.self).pointee = CFSInt128Struct.init(high: (val < 0) ? -1 : 0, low: UInt64(bitPattern: val))
break
case kCFNumberFloat32Type:
valuePtr.assumingMemoryBound(to: Float.self).pointee = floatValue
break
case kCFNumberFloat64Type:
valuePtr.assumingMemoryBound(to: Double.self).pointee = doubleValue
default: fatalError()
Expand All @@ -1106,7 +1100,6 @@ open class NSNumber : NSValue {
switch objCType.pointee {
case 0x42:
aCoder.encode(boolValue, forKey: "NS.boolval")
break
case 0x63: fallthrough
case 0x43: fallthrough
case 0x73: fallthrough
Expand Down
2 changes: 0 additions & 2 deletions TestFoundation/TestJSONEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,6 @@ func expectEqualPaths(_ lhs: [CodingKey?], _ rhs: [CodingKey?], _ prefix: String
XCTFail("\(prefix) CodingKey.intValue mismatch: \(type(of: key1))(\(i1)) != \(type(of: key2))(\(i2))")
return
}

break
}

XCTAssertEqual(key1.stringValue,
Expand Down