On Sun, 20 Feb 2022 18:20:27 GMT, liach <d...@openjdk.java.net> wrote:
>> XenoAmess has updated the pull request incrementally with three additional >> commits since the last revision: >> >> - refine test >> - 1. optimize IdentityHashMap that when calling ::new(Map), do not call >> map.size() twice but once. >> 2. delete the this((int) ((1 + m.size()) * 1.1)); as it makes the table >> over-allocate when size = 19. >> - refine test > > src/java.base/share/classes/java/util/IdentityHashMap.java line 281: > >> 279: * @throws NullPointerException if the specified map is null >> 280: */ >> 281: private IdentityHashMap(Map<? extends K, ? extends V> map, int >> expectedSize) { > > Why are you writing a new constructor when you can just change the old call > to `this(m.size());`? > @liach implementations `size()` seems O1, and returns a single int number > field, but it actually defers in some Map implementations. @liach for example, in ConcurrentSkipListMap and ConcurrentHashMap, `size()` function is far complicated than reading a field, thus calling it twice meaninglessly is not a wise choice. ------------- PR: https://git.openjdk.java.net/jdk/pull/7431