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 and this has been handeled. The check 
on hash is only used to detect if they are Not equal.
   When the hash is the same the code will do a value compare. 
   ```
   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);
   ```
   
   I think the biggest gain was in the has `if (this.hashCode() != 
o.hashCode()) {` for cases where there where a lot of rejects. 



-- 
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

Reply via email to