Prevent inlining of JSBody code in some complex cases

This commit is contained in:
Alexey Andreev 2018-11-16 19:04:15 +03:00
parent 148c07336c
commit e5c85dd3bd

View File

@ -44,7 +44,7 @@ final class JSBodyInlineUtil {
ComplexityCounter complexityCounter = new ComplexityCounter(); ComplexityCounter complexityCounter = new ComplexityCounter();
expression.visit(complexityCounter); expression.visit(complexityCounter);
if (complexityCounter.getComplexity() > COMPLEXITY_THRESHOLD) { if (complexityCounter.hasUnsupportedConstructs || complexityCounter.getComplexity() > COMPLEXITY_THRESHOLD) {
return null; return null;
} }
@ -86,6 +86,7 @@ final class JSBodyInlineUtil {
static class ComplexityCounter implements NodeVisitor { static class ComplexityCounter implements NodeVisitor {
private int complexity; private int complexity;
boolean hasUnsupportedConstructs;
public int getComplexity() { public int getComplexity() {
return complexity; return complexity;
@ -94,6 +95,13 @@ final class JSBodyInlineUtil {
@Override @Override
public boolean visit(AstNode node) { public boolean visit(AstNode node) {
++complexity; ++complexity;
switch (node.getType()) {
case Token.FUNCTION:
case Token.OBJECTLIT:
case Token.ARRAYLIT:
hasUnsupportedConstructs = true;
break;
}
return true; return true;
} }
} }