From f783244caf041b6f79036dfcf29ff857d9c1c78f Mon Sep 17 00:00:00 2001 From: Andrey Turbanov Date: Wed, 6 Jul 2022 06:40:19 +0000 Subject: [PATCH] 8289706: (cs) Avoid redundant TreeMap.containsKey call in AbstractCharsetProvider Reviewed-by: attila, naoto --- .../sun/nio/cs/ext/AbstractCharsetProvider.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/jdk.charsets/share/classes/sun/nio/cs/ext/AbstractCharsetProvider.java b/src/jdk.charsets/share/classes/sun/nio/cs/ext/AbstractCharsetProvider.java index 6c24819bd1b..d3ba1ced0f0 100644 --- a/src/jdk.charsets/share/classes/sun/nio/cs/ext/AbstractCharsetProvider.java +++ b/src/jdk.charsets/share/classes/sun/nio/cs/ext/AbstractCharsetProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,6 @@ import java.nio.charset.spi.CharsetProvider; import java.util.ArrayList; import java.util.TreeMap; import java.util.Iterator; -import java.util.Locale; import java.util.Map; @@ -75,14 +74,6 @@ public class AbstractCharsetProvider packagePrefix = pkgPrefixName.concat("."); } - /* Add an entry to the given map, but only if no mapping yet exists - * for the given name. - */ - private static void put(Map m, K name, V value) { - if (!m.containsKey(name)) - m.put(name, value); - } - private static void remove(Map m, K name) { V x = m.remove(name); assert (x != null); @@ -92,10 +83,10 @@ public class AbstractCharsetProvider */ protected void charset(String name, String className, String[] aliases) { synchronized (this) { - put(classMap, name, className); + classMap.putIfAbsent(name, className); for (int i = 0; i < aliases.length; i++) - put(aliasMap, aliases[i], name); - put(aliasNameMap, name, aliases); + aliasMap.putIfAbsent(aliases[i], name); + aliasNameMap.putIfAbsent(name, aliases); cache.clear(); } }