Skip to content

Commit

Permalink
Avoid string interning when cloning StringNodes.
Browse files Browse the repository at this point in the history
This shows up as the main cost of cloning AST trees, but it isn't necessary as we already know it is intern'd.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=173996784
  • Loading branch information
concavelenz authored and brad4d committed Oct 31, 2017
1 parent 60d2c63 commit cb4a8ad
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/com/google/javascript/rhino/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ private static final class StringNode extends Node {

private static final long serialVersionUID = 1L;

// Only for cloneNode
private StringNode(Token token) {
super(token);
}

StringNode(Token token, String str) {
super(token);
setString(str);
Expand Down Expand Up @@ -379,7 +384,9 @@ public void setQuotedString() {

@Override
public StringNode cloneNode(boolean cloneTypeExprs) {
return copyNodeFields(new StringNode(token, str), cloneTypeExprs);
StringNode clone = new StringNode(token);
clone.str = str;
return copyNodeFields(clone, cloneTypeExprs);
}

@GwtIncompatible("ObjectInputStream")
Expand Down

0 comments on commit cb4a8ad

Please sign in to comment.