imbajin commented on code in PR #2862:
URL:
https://github.com/apache/incubator-hugegraph/pull/2862#discussion_r2313278747
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/IdGenerator.java:
##########
@@ -174,25 +186,34 @@ public int compareTo(Id other) {
if (cmp != 0) {
return cmp;
}
- return this.id.compareTo(other.asString());
+ if (this.id != null) {
+ return this.id.compareTo(other.asString());
+ } else {
+ return Bytes.compare(this.bytes, other.asBytes());
+ }
}
@Override
public int hashCode() {
- return this.id.hashCode();
+ return this.asString().hashCode();
}
@Override
- public boolean equals(Object other) {
- if (!(other instanceof StringId)) {
+ public boolean equals(Object obj) {
+ if (!(obj instanceof StringId)) {
return false;
}
- return this.id.equals(((StringId) other).id);
+ StringId other = (StringId) obj;
+ if (this.id != null) {
+ return this.id.equals(other.asString());
+ } else {
Review Comment:
**Potential Memory Leak**: In the equals method, calling `other.asBytes()`
when `this.id != null` may trigger unnecessary byte array creation and caching
in the other object. Consider checking if the other object has the same
representation type first to avoid forced conversions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]