Details
-
Enhancement
-
Resolution: Fixed
-
P4
-
8, 11, 13, 14
-
None
Description
Currently HashMap.keySet().toArray(), HashMap.values().toArray(), HashSet.toArray(), LinkedHashMap.keySet().toArray(), LinkedHashMap.values().toArray(), LinkedHashSet.toArray() delegate to AbstractCollection implementation which creates an iterator. This is suboptimal as the corresponding iterator (e.g. HashMap.KeyIterator) should track current state which is quite non-trivial for HashMap. Also modCount is constantly compared with expectedModCount which is also redundant. It seems that existing JIT compilers (C2, Graal) cannot totally eliminate the overhead. I believe that these methods are used quite often (especially HashSet.toArray()) to deserve a specialized implementation similar to LinkedList.toArray().
Attachments
Issue Links
- csr for
-
JDK-8225393 Optimize HashMap.keySet()/HashMap.values()/HashSet toArray() methods
- Closed