RFR: 8305538: Avoid redundant HashMap.containsKey call in ModuleDescriptor.Builder

Andrey Turbanov aturbanov at openjdk.org
Tue Apr 4 12:40:05 UTC 2023


On Mon, 3 Apr 2023 08:08:45 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

> `Map.containsKey` call is sometimes unnecessary, when it's known that `Map` doesn't contain `null` values.
> Instead of pair containsKey+put we can use putIfAbsent and compare result with null.
> Result code is shorter and a bit faster.

Seems we can update `java.lang.module.ModuleDescriptor.Builder#uses` too to directly call `add` instead of `contains`+`add`

https://github.com/openjdk/jdk/blob/5881b099f6c23c9e8329af20a18f476d659f0079/src/java.base/share/classes/java/lang/module/ModuleDescriptor.java#L2015-L2018

-------------

PR Comment: https://git.openjdk.org/jdk/pull/13288#issuecomment-1495899800


More information about the core-libs-dev mailing list