RFR: 8284780: Need methods to create pre-sized HashSet and LinkedHashSet [v10]

Stuart Marks smarks at openjdk.java.net
Wed May 25 05:45:56 UTC 2022


On Tue, 24 May 2022 21:37:52 GMT, XenoAmess <duke at openjdk.java.net> wrote:

>> as title.
>
> XenoAmess has updated the pull request incrementally with one additional commit since the last revision:
> 
>   add test for newHashSet and newLinkedHashSet

I looked at all the use sites and they look fine. Some look like they could use additional cleanup, but that's probably beyond the scope of this change. (Also, I haven't seen `StringTokenizer` in a long time....) It's amazing how many bugs there are -- the majority look like they allocated the HashSet with the wrong capacity! Again, this proves the worth of these new APIs.

src/java.base/share/classes/java/util/HashSet.java line 398:

> 396:     public static <E> HashSet<E> newHashSet(int numItems) {
> 397:         return new HashSet<>(HashMap.calculateHashMapCapacity(numItems));
> 398:     }

Please use "elements" instead of "items" throughout the specifications for the objects that are members of the HashSet. This includes the API notes above as well as the specs and API notes in LinkedHashSet.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8302


More information about the core-libs-dev mailing list