Skip to content

Commit

Permalink
8302603: Use Set.of in java.nio.charset.Charset
Browse files Browse the repository at this point in the history
Reviewed-by: stsypanov, alanb, naoto
  • Loading branch information
Glavo authored and naotoj committed Feb 21, 2023
1 parent 10b4cc9 commit 5489c82
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/java.base/share/classes/java/nio/charset/Charset.java
Expand Up @@ -38,7 +38,6 @@
import java.security.PrivilegedAction;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -667,7 +666,7 @@ public static Charset defaultCharset() {

private final String name; // tickles a bug in oldjavac
private final String[] aliases; // tickles a bug in oldjavac
private Set<String> aliasSet = null;
private Set<String> aliasSet;

/**
* Initializes a new charset with the given canonical name and alias
Expand Down Expand Up @@ -714,14 +713,12 @@ public final String name() {
* @return An immutable set of this charset's aliases
*/
public final Set<String> aliases() {
if (aliasSet != null)
return aliasSet;
int n = aliases.length;
HashSet<String> hs = HashSet.newHashSet(n);
for (int i = 0; i < n; i++)
hs.add(aliases[i]);
aliasSet = Collections.unmodifiableSet(hs);
return aliasSet;
Set<String> set = this.aliasSet;
if (set == null) {
set = Set.of(aliases);
this.aliasSet = set;
}
return set;
}

/**
Expand Down

1 comment on commit 5489c82

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.