RFR: 8266571: Sequenced Collections [v5]
Stuart Marks
smarks at openjdk.org
Mon Apr 17 23:58:59 UTC 2023
On Thu, 30 Mar 2023 09:50:51 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:
>> src/java.base/share/classes/java/util/LinkedHashMap.java line 1197:
>>
>>> 1195:
>>> 1196: public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
>>> 1197: return base.computeIfAbsent(key, mappingFunction);
>>
>> Again, it's somewhat worrysome that methods like `computeIfAbsent` will actually add new nodes to the end of original LinkedHashMap instead of to the beginning. Probably not very big deal but looks inconsistent...
>
> Likely, for the first iteration it's possible to remove specializations for compute*/merge methods and use the default implementation from the `Map` interface, which will properly insert the new item to the beginning (if we properly implement reversed `put`). Later it could be optimized if necessary. What do you think?
Per my previous comment on put/putAll: if compute*/merge methods end up inserting a new entry, the entry should end up in the right place in insertion order (end of the backing map, or front of the reversed view) so all of these should be fine just delegating to the backing map.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/7387#discussion_r1169362682
More information about the core-libs-dev
mailing list