-
Notifications
You must be signed in to change notification settings - Fork 31
fix: skip unnecessary null checks in equals() methods for generated structures
#1346
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
This comment has been minimized.
This comment has been minimized.
1 similar comment
Affected ArtifactsNo artifacts changed size |
| .write("if (!#1L.contentEquals(other.#1L)) return false", memberName) | ||
| .closeBlock("} else if (other.#1L != null) return false", memberName) | ||
| } else { | ||
| write("if (!#1L.contentEquals(other.#1L)) return false", memberName) |
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.
Should we be checking the nullability of other.#1L? It's done in the block above
.write("if (other.#1L == null) return false", memberName)
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.
No, we're checking equality between two instances of the same shape. If this.foo cannot be null then other.foo cannot be null either.
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.
Ah, got it!
| .write("if (!#1L[i].contentEquals(other.#1L[i])) return false", memberName) | ||
| .closeBlock("}") | ||
| .closeBlock("} else if (other.#1L != null) return false", memberName) | ||
| } else { |
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.
Same comment as above
| .write("if (!#1L.contentEquals(other.#1L)) return false", memberName) | ||
| .closeBlock("} else if (other.#1L != null) return false", memberName) | ||
| } else { | ||
| write("if (!#1L.contentEquals(other.#1L)) return false", memberName) |
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.
Ah, got it!
Issue #
(none)
Description of changes
StructureGenerator's equality methods don't check for nullability of member symbols, leading to unnecessary null checks.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.