Skip to content
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

[jvm] Redundant ordinal check in enum equals #11591

Closed
Simn opened this issue Feb 23, 2024 · 0 comments
Closed

[jvm] Redundant ordinal check in enum equals #11591

Simn opened this issue Feb 23, 2024 · 0 comments
Assignees
Labels
platform-jvm Everything related to JVM

Comments

@Simn
Copy link
Member

Simn commented Feb 23, 2024

Looking at what I posted in SomeRanDev/reflaxe.CSharp#2 (comment) again, I noticed this:

        public boolean equals(Enum other) {
            if (!(other instanceof Option.Some)) {
                return false;
            } else {
                Option.Some other = (Option.Some)other;
                if (other.ordinal() != this.ordinal()) {
                    return false;
                } else {
                    return Jvm.maybeEnumEq(other.v, this.v);
                }
            }
        }

The if (other.ordinal() != this.ordinal()) check seems redundant because we already know that enums of the same class have the same ordinal by design.

@Simn Simn added the platform-jvm Everything related to JVM label Feb 23, 2024
@Simn Simn self-assigned this Feb 23, 2024
@Simn Simn closed this as completed in 5957d97 Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform-jvm Everything related to JVM
Projects
None yet
Development

No branches or pull requests

1 participant