Skip to content

Commit 78feee0

Browse files
Andrey Turbanovr30shah
authored andcommitted
8289706: (cs) Avoid redundant TreeMap.containsKey call in AbstractCharsetProvider
Reviewed-by: attila, naoto
1 parent 6e622ae commit 78feee0

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/jdk.charsets/share/classes/sun/nio/cs/ext/AbstractCharsetProvider.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,6 @@
3131
import java.util.ArrayList;
3232
import java.util.TreeMap;
3333
import java.util.Iterator;
34-
import java.util.Locale;
3534
import java.util.Map;
3635

3736

@@ -75,14 +74,6 @@ protected AbstractCharsetProvider(String pkgPrefixName) {
7574
packagePrefix = pkgPrefixName.concat(".");
7675
}
7776

78-
/* Add an entry to the given map, but only if no mapping yet exists
79-
* for the given name.
80-
*/
81-
private static <K,V> void put(Map<K,V> m, K name, V value) {
82-
if (!m.containsKey(name))
83-
m.put(name, value);
84-
}
85-
8677
private static <K,V> void remove(Map<K,V> m, K name) {
8778
V x = m.remove(name);
8879
assert (x != null);
@@ -92,10 +83,10 @@ private static <K,V> void remove(Map<K,V> m, K name) {
9283
*/
9384
protected void charset(String name, String className, String[] aliases) {
9485
synchronized (this) {
95-
put(classMap, name, className);
86+
classMap.putIfAbsent(name, className);
9687
for (int i = 0; i < aliases.length; i++)
97-
put(aliasMap, aliases[i], name);
98-
put(aliasNameMap, name, aliases);
88+
aliasMap.putIfAbsent(aliases[i], name);
89+
aliasNameMap.putIfAbsent(name, aliases);
9990
cache.clear();
10091
}
10192
}

0 commit comments

Comments
 (0)