mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-11 10:58:26 +00:00
8055911: Don't use String.intern for IdentNode
Reviewed-by: lagergren, sundar
This commit is contained in:
parent
b04e423d8d
commit
2fc5ea4674
@ -71,7 +71,7 @@ public final class IdentNode extends Expression implements PropertyKey, Function
|
||||
*/
|
||||
public IdentNode(final long token, final int finish, final String name) {
|
||||
super(token, finish);
|
||||
this.name = name.intern();
|
||||
this.name = name;
|
||||
this.type = null;
|
||||
this.flags = 0;
|
||||
this.programPoint = INVALID_PROGRAM_POINT;
|
||||
|
||||
@ -31,6 +31,8 @@ import static jdk.nashorn.internal.parser.TokenType.EOF;
|
||||
import static jdk.nashorn.internal.parser.TokenType.EOL;
|
||||
import static jdk.nashorn.internal.parser.TokenType.IDENT;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import jdk.nashorn.internal.ir.IdentNode;
|
||||
import jdk.nashorn.internal.ir.LiteralNode;
|
||||
import jdk.nashorn.internal.parser.Lexer.LexerToken;
|
||||
@ -91,6 +93,8 @@ public abstract class AbstractParser {
|
||||
/** What should line numbers be counted from? */
|
||||
protected final int lineOffset;
|
||||
|
||||
private final Map<String, String> canonicalNames = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Construct a parser.
|
||||
*
|
||||
@ -409,7 +413,7 @@ public abstract class AbstractParser {
|
||||
next();
|
||||
|
||||
// Create IDENT node.
|
||||
return new IdentNode(identToken, finish, ident).setIsFutureStrictName();
|
||||
return createIdentNode(identToken, finish, ident).setIsFutureStrictName();
|
||||
}
|
||||
|
||||
// Get IDENT.
|
||||
@ -418,7 +422,22 @@ public abstract class AbstractParser {
|
||||
return null;
|
||||
}
|
||||
// Create IDENT node.
|
||||
return new IdentNode(identToken, finish, ident);
|
||||
return createIdentNode(identToken, finish, ident);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link IdentNode} as if invoked with a {@link IdentNode#IdentNode(long, int, String)
|
||||
* constructor} but making sure that the {@code name} is deduplicated within this parse job.
|
||||
* @param identToken the token for the new {@code IdentNode}
|
||||
* @param identFinish the finish for the new {@code IdentNode}
|
||||
* @param name the name for the new {@code IdentNode}. It will be de-duplicated.
|
||||
* @return a newly constructed {@code IdentNode} with the specified token, finish, and name; the name will
|
||||
* be deduplicated.
|
||||
*/
|
||||
protected IdentNode createIdentNode(final long identToken, final int identFinish, final String name) {
|
||||
final String existingName = canonicalNames.putIfAbsent(name, name);
|
||||
final String canonicalName = existingName != null ? existingName : name;
|
||||
return new IdentNode(identToken, identFinish, canonicalName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -453,7 +472,7 @@ public abstract class AbstractParser {
|
||||
final String ident = (String)getValue(identToken);
|
||||
next();
|
||||
// Create IDENT node.
|
||||
return new IdentNode(identToken, finish, ident);
|
||||
return createIdentNode(identToken, finish, ident);
|
||||
} else {
|
||||
expect(IDENT);
|
||||
return null;
|
||||
|
||||
@ -222,7 +222,7 @@ public class Parser extends AbstractParser implements Loggable {
|
||||
* @param name the name for the first parsed function.
|
||||
*/
|
||||
public void setFunctionName(final String name) {
|
||||
defaultNames.push(new IdentNode(0, 0, name));
|
||||
defaultNames.push(createIdentNode(0, 0, name));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2243,7 +2243,7 @@ loop:
|
||||
}
|
||||
}
|
||||
|
||||
propertyName = new IdentNode(propertyToken, finish, ident).setIsPropertyName();
|
||||
propertyName = createIdentNode(propertyToken, finish, ident).setIsPropertyName();
|
||||
} else {
|
||||
propertyName = propertyName();
|
||||
}
|
||||
@ -2261,7 +2261,7 @@ loop:
|
||||
private PropertyFunction propertyGetterFunction(final long getSetToken, final int functionLine) {
|
||||
final PropertyKey getIdent = propertyName();
|
||||
final String getterName = getIdent.getPropertyName();
|
||||
final IdentNode getNameNode = new IdentNode(((Node)getIdent).getToken(), finish, NameCodec.encode("get " + getterName));
|
||||
final IdentNode getNameNode = createIdentNode(((Node)getIdent).getToken(), finish, NameCodec.encode("get " + getterName));
|
||||
expect(LPAREN);
|
||||
expect(RPAREN);
|
||||
final FunctionNode functionNode = functionBody(getSetToken, getNameNode, new ArrayList<IdentNode>(), FunctionNode.Kind.GETTER, functionLine);
|
||||
@ -2272,7 +2272,7 @@ loop:
|
||||
private PropertyFunction propertySetterFunction(final long getSetToken, final int functionLine) {
|
||||
final PropertyKey setIdent = propertyName();
|
||||
final String setterName = setIdent.getPropertyName();
|
||||
final IdentNode setNameNode = new IdentNode(((Node)setIdent).getToken(), finish, NameCodec.encode("set " + setterName));
|
||||
final IdentNode setNameNode = createIdentNode(((Node)setIdent).getToken(), finish, NameCodec.encode("set " + setterName));
|
||||
expect(LPAREN);
|
||||
// be sloppy and allow missing setter parameter even though
|
||||
// spec does not permit it!
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user