Fix performance regression caused by contracts

Do not obtain all children from KtBlockExpression when you only need
the first one.
It might be crucial for a huge blocks of code
This commit is contained in:
Denis Zharkov
2019-05-28 15:51:15 +03:00
parent 16d05b6129
commit 753a9a1c36
2 changed files with 7 additions and 2 deletions
@@ -123,6 +123,11 @@ public class KtBlockExpression extends LazyParseablePsiElement implements KtElem
return substitute != null ? substitute : super.getParent(); return substitute != null ? substitute : super.getParent();
} }
@Nullable
public KtExpression getFirstStatement() {
return findChildByClass(KtExpression.class);
}
@ReadOnly @ReadOnly
@NotNull @NotNull
public List<KtExpression> getStatements() { public List<KtExpression> getStatements() {
@@ -323,7 +323,7 @@ fun KtElement.isFirstStatement(): Boolean {
element = parent element = parent
parent = parent.parent parent = parent.parent
} }
return parent is KtBlockExpression && parent.children.first { it is KtElement } == element return parent is KtBlockExpression && parent.firstStatement == element
} }
@@ -671,4 +671,4 @@ fun KtExpression.topParenthesizedParentOrMe(): KtExpression {
result = result.parent.safeAs() ?: break result = result.parent.safeAs() ?: break
} }
return result return result
} }