RFR: 8256167: Convert JDK use of `Reference::get` to `Reference::refersTo`
Peter Levart
plevart at openjdk.java.net
Fri Dec 4 20:20:11 UTC 2020
On Fri, 4 Dec 2020 20:09:01 GMT, Mandy Chung <mchung at openjdk.org> wrote:
>> src/java.base/share/classes/java/util/WeakHashMap.java line 293:
>>
>>> 291: // then checks for equality
>>> 292: Object k = e.get();
>>> 293: return key == k || key.equals(k);
>>
>> I think `key == k` is already covered by refersTo. But k could be null; checking for that here might be useful, to skip the call to equals in that case.
>
> Good point on checking k != null. A cleaner check:
>
> // then check for equality if the referent is not cleared
> Object k = e.get();
> return k != null || key.equals(k);
You meant: `return k != null && key.equals(k);` right?
-------------
PR: https://git.openjdk.java.net/jdk/pull/1609
More information about the core-libs-dev
mailing list