<i18n dev> RFR: 8186958: Need method to create pre-sized HashMap [v18]

Joe Wang joehw at openjdk.java.net
Thu Apr 14 03:42:16 UTC 2022


On Thu, 14 Apr 2022 01:13:18 GMT, XenoAmess <duke at openjdk.java.net> wrote:

>> src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSAttributeChecker.java line 1819:
>> 
>>> 1817:     Map<String, OneAttr> items;
>>> 1818:     LargeContainer(int size) {
>>> 1819:         items = HashMap.newHashMap(size*2+1);
>> 
>> I'm wondering if we should change this to just `newHashMap(size)` since it looks like this container is intended to hold up to `size` items. @JoeWang-Java ? I suspect the `size*2+1` was a failed attempt at allocating a HashMap of the correct capacity for `size` mappings.
>
>> I suspect the `size*2+1` was a failed attempt at allocating a HashMap of the correct capacity for `size` mappings.
> 
> I looked the codes and don't think so..
> If I'm wrong, I'm glad to fix.

Stuart's right, I looked at the code, it's as you said a failed attempt, "size" would be good. So HashMap.newHashMap(size) would actually be a small improvement.

It's an interesting impl the way it used HashMap, but it's 20 year code.

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

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


More information about the i18n-dev mailing list