-
Notifications
You must be signed in to change notification settings - Fork 499
Oneof cleanup and generation improvements. #477
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
Conversation
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] { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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].
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
tbkka
left a comment
There was a problem hiding this 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)]) |
There was a problem hiding this comment.
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.
Fixes #369.