Re: RFR: 8293630: Simplify TreeMap.get() with Comparator.naturalOrder() [v2]

2022-10-14 Thread ExE Boss
On Fri, 14 Oct 2022 08:53:24 GMT, Сергей Цыпанов  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>

src/java.base/share/classes/java/util/TreeMap.java line 3320:

> 3318: @SuppressWarnings("unchecked")
> 3319: Comparator> entryComparator = 
> treeComparator == null ?
> 3320: (Comparator) Map.Entry.comparingByKey()

Missed a colon:
Suggestion:

(Comparator) Map.Entry.comparingByKey() :

-

PR: https://git.openjdk.org/jdk/pull/9901


Re: RFR: 8293630: Simplify TreeMap.get() with Comparator.naturalOrder() [v2]

2022-10-14 Thread Сергей Цыпанов
On Thu, 13 Oct 2022 21:46:15 GMT, ExE Boss  wrote:

>> Nope, there'd be a compilation error
>
> It'll work fine if an unchecked cast is used:
> Suggestion:
> 
> @SuppressWarnings("unchecked")
> Comparator> entryComparator = treeComparator == 
> null ?
> (Comparator) Map.Entry.comparingByKey()
> Map.Entry.comparingByKey(treeComparator);
> return entryComparator;
> 
> 
> This also ensures that when `treeComparator` is `null`, this method keeps 
> returning a constant lambda.

This one looks fine, accepted.

-

PR: https://git.openjdk.org/jdk/pull/9901


Re: RFR: 8293630: Simplify TreeMap.get() with Comparator.naturalOrder() [v2]

2022-10-14 Thread Сергей Цыпанов
> 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>

-

Changes:
  - all: https://git.openjdk.org/jdk/pull/9901/files
  - new: https://git.openjdk.org/jdk/pull/9901/files/259348a7..ab4cfa2c

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk=9901=01
 - incr: https://webrevs.openjdk.org/?repo=jdk=9901=00-01

  Stats: 5 lines in 1 file changed: 4 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/9901.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/9901/head:pull/9901

PR: https://git.openjdk.org/jdk/pull/9901