On Fri, 14 Oct 2022 19:03:11 GMT, Сергей Цыпанов <d...@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-b...@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