-
Type:
CSR
-
Resolution: Approved
-
Priority:
P4
-
Component/s: core-libs
-
None
-
behavioral
-
low
-
-
Java API
-
SE
Summary
Specialized implementations of the TreeMap methods putIfAbsent, computeIfAbsent, computeIfPresent, compute, and merge are introduced.
Problem
Default implementations of the putIfAbsent, computeIfAbsent, computeIfPresent, compute, and merge methods provided by AbstractMap delegate to the get, put, and remove methods, which may require traversing the tree twice. An optimized implementation can traverse the tree only once. This can provide a noticeable speedup, especially if the comparison method is expensive.
Solution
Provide optimized implementations for these methods, similar to HashMap.
Specification
-
As
TreeMapnow overrides the methodsputIfAbsent,computeIfAbsent,computeIfPresent,compute, andmerge, theimplSpecsection specified for the corresponding default methods in theMapinterface is no longer relevant toTreeMapmethods. -
The specification for the
TreeMapmethodcomputeIfAbsentnow additionally covers the concurrent update policy, as follows:
* <p>This method will, on a best-effort basis, throw a
* {@link ConcurrentModificationException} if it is detected that the
* mapping function modifies this map during computation.
*
* @throws ConcurrentModificationException if it is detected that the
* mapping function modified this map
- The specifications for the
TreeMapmethodscomputeIfPresent,compute, andmergenow additionally cover the concurrent update policy, as follows:
* <p>This method will, on a best-effort basis, throw a
* {@link ConcurrentModificationException} if it is detected that the
* remapping function modifies this map during computation.
*
* @throws ConcurrentModificationException if it is detected that the
* remapping function modified this map
These additions are exactly copied from the specification of the corresponding HashMap methods.
- csr of
-
JDK-8176894 Provide specialized implementation for default methods putIfAbsent, computeIfAbsent, computeIfPresent, compute, merge in TreeMap
-
- Resolved
-