borisssmidtCET commented on code in PR #14597: URL: https://github.com/apache/kafka/pull/14597#discussion_r1415306650
########## clients/src/main/java/org/apache/kafka/common/security/auth/KafkaPrincipal.java: ########## @@ -68,9 +73,15 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null) return false; if (getClass() != o.getClass()) return false; - KafkaPrincipal that = (KafkaPrincipal) o; - return principalType.equals(that.principalType) && name.equals(that.name); + + // hashes are cached, so this goes quicker than the string compare + if (this.hashCode() != o.hashCode()) { Review Comment: You are correct that they can collide, but if the hashCode of 2 strings don't match then they are for sure not the same. I.e. ``` A.hashcode() != B.hashcode() == true => they are not the same A.hashcode() != B.hashcode() == false => they are the same OR they collide //Hence the check after this to do the value compare: return name.equals(that.name) && principalType.equals(that.principalType); ``` -- 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: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org