[PATCH] Simplification of TreeMap
sergei.tsypanov at yandex.ru
Tue Sep 4 19:14:21 UTC 2018
currently (latest code of JDK 11) an instance of TreeMap created with no-arg contructor has nullable comparator i.e. utilizes no comparator.
As it comes from the code, a TreeMap created with nullable comparator works exactly as a TreeMap created with comparator provided by Comparator.naturalOrder(). This is also explicitly specifid in Javadoc.
I propose to initialize default comparator of TreeMap with instance of Comparator returned by Comparator.naturalOrder() instead of null.
This allows to remove the code responsible for handling nullable comparator, e. g. TreeMap::getEntryUsingComparator can be completely removed in favour of TreeMap::getEntry.
Similar simplification available for TreeMap::put, TreeMap::compare, EntrySpliterator::getComparator.
I've prepared a patch for this.
The patch contains both described major change and some tiny clean-ups e. g. utilization of Objects::requireNonNull where appropriate and Objects::equals instead of hand-written TreeMap::valEquals.
TreeMapTest is green after my changes.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 13581 bytes
Desc: not available
More information about the core-libs-dev