Skip to content

Commit

Permalink
Derive the hash code from the object id, which is more efficient than…
Browse files Browse the repository at this point in the history
… the default identity hash code. Also clean up the string representation.
  • Loading branch information
broneill committed Oct 5, 2024
1 parent c97c18b commit 575ed2c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/main/java/org/cojen/dirmi/core/Stub.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,25 @@ protected Stub(long id) {
abstract StubInvoker invoker();

@Override
public String toString() {
public final int hashCode() {
return Long.hashCode(id);
}

@Override
public final String toString() {
var b = new StringBuilder();

String name = getClass().getName();

// Prune off the generated suffix.
int ix = name.lastIndexOf('-');
if (ix > 0) {
name = name.substring(0, ix);
if (ix < 0) {
b.append(name);
} else {
// Prune off the generated suffix.
b.append(name, 0, ix);
}

var b = new StringBuilder();

b.append(name).append('@').append(Integer.toHexString(System.identityHashCode(this)))
.append("{id=").append(id);
b.append("{id=").append(id);

support().appendInfo(b);

Expand Down

0 comments on commit 575ed2c

Please sign in to comment.