8268622: Performance issues in javac Name class

Reviewed-by: vromero
This commit is contained in:
Archie Cobbs 2023-10-02 20:15:43 +00:00 committed by Vicente Romero
parent ad81abd2db
commit 5c8366eea4
2 changed files with 15 additions and 12 deletions

View File

@ -428,17 +428,18 @@ public class Names {
}
protected Name.Table createTable(Options options) {
boolean useStringTable = options.isSet("useStringTable");
if (useStringTable)
return newStringNameTable();
boolean useUnsharedTable = options.isSet("useUnsharedTable");
if (useUnsharedTable)
return newUnsharedNameTable();
return newSharedNameTable();
boolean useSharedTable = options.isSet("useSharedTable");
if (useSharedTable)
return newSharedNameTable();
boolean internStringTable = options.isSet("internStringTable");
return newStringNameTable(internStringTable);
}
public StringNameTable newStringNameTable() {
return StringNameTable.create(this);
public StringNameTable newStringNameTable(boolean intern) {
return StringNameTable.create(this, intern);
}
public SharedNameTable newSharedNameTable() {

View File

@ -38,29 +38,31 @@ import java.util.HashMap;
public class StringNameTable extends Name.Table {
private final HashMap<String, Name> nameMap;
private final boolean intern;
// Factory
public static StringNameTable create(Names names) {
return new StringNameTable(names);
public static StringNameTable create(Names names, boolean intern) {
return new StringNameTable(names, intern);
}
// Constructors
public StringNameTable(Names names) {
this(names, 0x8000);
public StringNameTable(Names names, boolean intern) {
this(names, 0x8000, intern);
}
public StringNameTable(Names names, int initialCapacity) {
public StringNameTable(Names names, int initialCapacity, boolean intern) {
super(names);
this.nameMap = new HashMap<>(initialCapacity);
this.intern = intern;
}
// Name.Table
@Override
public Name fromString(String string) {
return this.nameMap.computeIfAbsent(string, s -> new NameImpl(this, s));
return this.nameMap.computeIfAbsent(string, s -> new NameImpl(this, intern ? s.intern() : s));
}
@Override