RFR: 8287602: (fs) Avoid redundant HashMap.containsKey call in MimeTypesFileTypeDetector.putIfAbsent
Andrey Turbanov
aturbanov at openjdk.java.net
Tue May 31 21:08:25 UTC 2022
On Tue, 31 May 2022 13:14:42 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> Only non-null values are put into `Map<String,String> mimeTypeMap`. It means, we can replace `containsKey`+`put` calls with single `putIfAbsent` call. It makes code a bit cleaner and faster.
>>
>> https://github.com/openjdk/jdk/blob/3d2d039538b906cedd9188ed94b7ba55c275ff7f/src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java#L189-L196
>
> src/java.base/unix/classes/sun/nio/fs/MimeTypesFileTypeDetector.java line 191:
>
>> 189: private void putIfAbsent(String key, String value) {
>> 190: if (key != null && !key.isEmpty() &&
>> 191: value != null && !value.isEmpty())
>
> The change looks okay. While you there then it would be okay to combine these two lines into one to avoid the unusual formatting.
Done. Also I did remove redundant null checks. Method `putIfAbsent` is called in 2 places and in both places, parameters are guaranteed to be non-null.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8941
More information about the nio-dev
mailing list