Skip to content

Commit

Permalink
Clean up hashCode/equals in IntVersion.
Browse files Browse the repository at this point in the history
Avoid creating a boxed `Long`, and add the typical fast-path for reference equality.

PiperOrigin-RevId: 418983086
  • Loading branch information
justinhorvitz authored and copybara-github committed Dec 30, 2021
1 parent 1160485 commit 2d93032
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/main/java/com/google/devtools/build/skyframe/IntVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ public boolean atMost(Version other) {

@Override
public int hashCode() {
return Long.valueOf(val).hashCode();
return Long.hashCode(val);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof IntVersion) {
IntVersion other = (IntVersion) obj;
return other.val == val;
if (this == obj) {
return true;
}
return false;
if (!(obj instanceof IntVersion)) {
return false;
}
IntVersion other = (IntVersion) obj;
return other.val == val;
}

@Override
Expand Down

0 comments on commit 2d93032

Please sign in to comment.