[PATCH] Simplification of TreeMap
forax at univ-mlv.fr
Tue Sep 4 19:41:47 UTC 2018
if think the code is as it is because it's faster to check for the null comparator and have an ad-hoc code for this special case than using Comparator.naturalOrder(),
obviously, it's not may be true anymore, so you should test that there is no perf regression when creating your patch.
----- Mail original -----
> De: "Сергей Цыпанов" <sergei.tsypanov at yandex.ru>
> À: "core-libs-dev" <core-libs-dev at openjdk.java.net>
> Envoyé: Mardi 4 Septembre 2018 21:14:21
> Objet: [PATCH] Simplification of TreeMap
> 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
> Similar simplification available for TreeMap::put, TreeMap::compare,
> 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.
> Sergey Tsypanov
More information about the core-libs-dev