-
CSR
-
Resolution: Approved
-
P4
-
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
TreeMap
now overrides the methodsputIfAbsent
,computeIfAbsent
,computeIfPresent
,compute
, andmerge
, theimplSpec
section specified for the corresponding default methods in theMap
interface is no longer relevant toTreeMap
methods.The specification for the
TreeMap
methodcomputeIfAbsent
now 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
TreeMap
methodscomputeIfPresent
,compute
, andmerge
now 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