RFR: 8293630: Simplify TreeMap.get() with Comparator.naturalOrder() [v3]
Tagir F. Valeev
tvaleev at openjdk.org
Sun Oct 16 19:45:57 UTC 2022
On Fri, 14 Oct 2022 19:03:11 GMT, Сергей Цыпанов <duke at openjdk.org> wrote:
>> We can use `Comparator.naturalOrder()` for cases when a `TreeMap` instance is constructed without comparator. This allows to squash two branches in `TreeMap.get()` into one.
>>
>> P.S. I think the comment of `TreeMap.getEntryUsingComparator()` is outdated. Should we also change it?
>
> Сергей Цыпанов has updated the pull request incrementally with one additional commit since the last revision:
>
> Update src/java.base/share/classes/java/util/TreeMap.java
>
> Co-authored-by: ExE Boss <3889017+ExE-Boss at users.noreply.github.com>
I saw this code many times and always thought that it exists for performance purposes, to avoid extra indirection via likely megamorphic naturalOrder comparator which will slow down the operations on common path. I think such a simplification could be accepted only if accompanied by a properly written benchmark (which actually emulates megamorphic callsite) which shows no performance regression.
-------------
PR: https://git.openjdk.org/jdk/pull/9901
More information about the core-libs-dev
mailing list