RFR: 8287285: Avoid redundant HashMap.containsKey call in java.util.zip.ZipFile.Source.get

Andrey Turbanov aturbanov at openjdk.java.net
Wed May 25 08:05:16 UTC 2022


The method `java.util.zip.ZipFile.Source#get` could be improved by usage of `Map.putIfAbsent` instead of separate `containsKey`/`get`/`put` calls. We known that HashMap `java.util.zip.ZipFile.Source#files` can contain only non-null values. And to check if putIfAbsent was successful or not we can just compare result with `null`.
It makes code a bit cleaner and faster.

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

Commit messages:
 - [PATCH] Avoid redundant Map.containsKey in ZipFile

Changes: https://git.openjdk.java.net/jdk/pull/8481/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=8481&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8287285
  Stats: 6 lines in 1 file changed: 0 ins; 1 del; 5 mod
  Patch: https://git.openjdk.java.net/jdk/pull/8481.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/8481/head:pull/8481

PR: https://git.openjdk.java.net/jdk/pull/8481


More information about the core-libs-dev mailing list