Skip to content

Commit 7997221

Browse files
committed
Use an array slice to check if the oneof fields are continuous in the parent.
1 parent b6bd276 commit 7997221

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

Sources/protoc-gen-swift/OneofGenerator.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,9 @@ class OneofGenerator {
7171
// }
7272
// int32 m = 13;
7373
// }
74+
let sortedOneofFieldNumbers = fieldsSortedByNumber.map { $0.number }
7475
let firstIndex = parentFieldNumbersSorted.index(of: first)!
75-
var isContinuousInParent = true
76-
for i in 0..<fields.count {
77-
if fieldsSortedByNumber[i].number != parentFieldNumbersSorted[firstIndex + i] {
78-
isContinuousInParent = false
79-
break
80-
}
81-
}
76+
var isContinuousInParent = sortedOneofFieldNumbers == Array(parentFieldNumbersSorted[firstIndex..<(firstIndex + fields.count)])
8277
if isContinuousInParent {
8378
// Make sure there isn't an extension range in the middle of the fields.
8479
// message AlsoBad {

0 commit comments

Comments
 (0)