Skip to content

Commit

Permalink
Defer asking for the TypeRegistry in ReplaceCssName till it is actual…
Browse files Browse the repository at this point in the history
…ly needed.

In my tests this saves 12ms in my minimal build test, which doesn't do type checking, with the GWT version of the compiler.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=130951427
  • Loading branch information
concavelenz authored and brad4d committed Aug 23, 2016
1 parent f1a7fe8 commit de5fc00
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/com/google/javascript/jscomp/ReplaceCssNames.java
Expand Up @@ -81,7 +81,7 @@
*/
class ReplaceCssNames implements CompilerPass {

static final String GET_CSS_NAME_FUNCTION = "goog.getCssName";
static final Node GET_CSS_NAME_FUNCTION = IR.getprop(IR.name("goog"), IR.string("getCssName"));

static final DiagnosticType INVALID_NUM_ARGUMENTS_ERROR =
DiagnosticType.error("JSC_GETCSSNAME_NUM_ARGS",
Expand Down Expand Up @@ -112,18 +112,25 @@ class ReplaceCssNames implements CompilerPass {

private final Set<String> whitelist;

private final TypeI nativeStringType;
private TypeI nativeStringType;

ReplaceCssNames(AbstractCompiler compiler,
@Nullable Map<String, Integer> cssNames,
@Nullable Set<String> whitelist) {
this.compiler = compiler;
this.cssNames = cssNames;
this.whitelist = whitelist;
this.nativeStringType =
}

private TypeI getNativeStringType() {
if (nativeStringType == null) {
nativeStringType =
compiler.getTypeIRegistry().getNativeType(STRING_TYPE);
}
return nativeStringType;
}


@Override
public void process(Node externs, Node root) {
// The CssRenamingMap may not have been available from the compiler when
Expand Down Expand Up @@ -180,7 +187,7 @@ public void visit(NodeTraversal t, Node n, Node parent) {
IR.string("-" + second.getString())
.useSourceInfoIfMissingFrom(second))
.useSourceInfoIfMissingFrom(n);
replacement.setTypeI(nativeStringType);
replacement.setTypeI(getNativeStringType());
parent.replaceChild(n, replacement);
compiler.reportCodeChange();
}
Expand Down

0 comments on commit de5fc00

Please sign in to comment.