Skip to content

Commit

Permalink
Honor @noinline in InlineFunctions.
Browse files Browse the repository at this point in the history
Related to #2751

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179759191
  • Loading branch information
brad4d authored and Tyler Breisacher committed Dec 21, 2017
1 parent 5698304 commit 9cc62fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/com/google/javascript/jscomp/InlineFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.javascript.jscomp.FunctionInjector.CanInlineResult;
import com.google.javascript.jscomp.FunctionInjector.InliningMode;
import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;
import com.google.javascript.rhino.JSDocInfo;
import com.google.javascript.rhino.Node;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -262,6 +263,12 @@ void maybeAddFunction(Function fn, JSModule module) {
return;
}
Node fnNode = fn.getFunctionNode();

if (hasNoInlineAnnotation(fnNode)) {
functionState.setInline(false);
return;
}

if (enforceMaxSizeAfterInlining
&& !isAlwaysInlinable(fnNode)
&& maxSizeAfterInlining <= NodeUtil.countAstSizeUpToLimit(fnNode, maxSizeAfterInlining)) {
Expand Down Expand Up @@ -328,6 +335,11 @@ void maybeAddFunction(Function fn, JSModule module) {
}
}

private boolean hasNoInlineAnnotation(Node fnNode) {
JSDocInfo jsDocInfo = NodeUtil.getBestJSDocInfo(fnNode);
return jsDocInfo != null && jsDocInfo.isNoInline();
}

/**
* @param fnNode The function to inspect.
* @return Whether the function has parameters, var/const/let, class, or function declarations.
Expand Down
5 changes: 5 additions & 0 deletions test/com/google/javascript/jscomp/InlineFunctionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ protected int getNumRepetitions() {
return 3;
}

public void testNoInline() {
testSame("/** @noinline */ function foo(){} foo();foo();foo();");
testSame("/** @noinline */ var foo = function(){}; foo();foo();foo();");
}

public void testInlineEmptyFunction1() {
// Empty function, no params.
test("function foo(){}" +
Expand Down

0 comments on commit 9cc62fa

Please sign in to comment.