Skip to content

Conversation

@thomasvl
Copy link
Collaborator

Fixes #369.

If the oneof fields are continuous in the parent, optimize the generation
to avoid having to pass a start/stop range.
Handle gaps in the oneof field numbers not needing to use ranges when
traversing.
let firstIndex = parentFieldNumbersSorted.index(of: first)!
var isContinuousInParent = true
for i in 0..<fields.count {
if fieldsSortedByNumber[i].number != parentFieldNumbersSorted[firstIndex + i] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this logic a little confusing. It would be clearer (to me) to use the same logic as you use for extension checks below, namely: Are any of the parent field numbers between our first and last field numbers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch is the parent list includes the fields in this oneof, so it would be a little more complicated.

Another solution (which I didn't try coding) could be to see if sortedFields == parentFields[firstIndex..<firstIndex+fields.count].

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or subtract our fields from the parent fields (set logic), then do the same check as extensions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was able to use the slice, how does this seem?

Copy link
Collaborator

@tbkka tbkka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice cleanup. The generated code here reads a lot more naturally.

break
}
}
var isContinuousInParent = sortedOneofFieldNumbers == Array(parentFieldNumbersSorted[firstIndex..<(firstIndex + fields.count)])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler doesn't like the compare without the Array() around it (saying you can't compare an Array with and ArraySlice.

@thomasvl thomasvl merged commit a28c252 into apple:master Apr 11, 2017
@thomasvl thomasvl deleted the oneof_cleanup branch April 11, 2017 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants