You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/02/18 17:38:49 UTC

[GitHub] [kafka] splett2 commented on a change in pull request #11754: MINOR: Optimize collection method in Utils

splett2 commented on a change in pull request #11754:
URL: https://github.com/apache/kafka/pull/11754#discussion_r810211960



##########
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##########
@@ -764,10 +764,7 @@ public static ByteBuffer ensureCapacity(ByteBuffer existingBuffer, int newLength
      */
     @SafeVarargs
     public static <T> Set<T> mkSet(T... elems) {
-        Set<T> result = new HashSet<>((int) (elems.length / 0.75) + 1);
-        for (T elem : elems)
-            result.add(elem);
-        return result;
+        return new HashSet<>(Arrays.asList(elems));

Review comment:
       This microbenchmark doesn't seem to be written correctly.
   you are creating a singleton list of a primitive array in `testCreateHashSet1`.
   
   `inits` needs to be an `Integer` array rather than a primitive array to get the expected array/hashset behavior.




-- 
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-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org