Optimize recursive string concatenation
This commit is contained in:
@@ -3184,7 +3184,9 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void invokeAppend(KtExpression expr) {
|
public void invokeAppend(KtExpression expr) {
|
||||||
if (expr instanceof KtBinaryExpression) {
|
ConstantValue<?> compileTimeConstant = getPrimitiveOrStringCompileTimeConstant(expr, bindingContext);
|
||||||
|
|
||||||
|
if (compileTimeConstant == null && expr instanceof KtBinaryExpression) {
|
||||||
KtBinaryExpression binaryExpression = (KtBinaryExpression) expr;
|
KtBinaryExpression binaryExpression = (KtBinaryExpression) expr;
|
||||||
if (binaryExpression.getOperationToken() == KtTokens.PLUS) {
|
if (binaryExpression.getOperationToken() == KtTokens.PLUS) {
|
||||||
KtExpression left = binaryExpression.getLeft();
|
KtExpression left = binaryExpression.getLeft();
|
||||||
@@ -3198,8 +3200,13 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Type exprType = expressionType(expr);
|
Type exprType = expressionType(expr);
|
||||||
gen(expr, exprType);
|
if (compileTimeConstant != null) {
|
||||||
|
StackValue.constant(compileTimeConstant.getValue(), exprType).put(exprType, v);
|
||||||
|
} else {
|
||||||
|
gen(expr, exprType);
|
||||||
|
}
|
||||||
genInvokeAppendMethod(v, exprType.getSort() == Type.ARRAY ? OBJECT_TYPE : exprType);
|
genInvokeAppendMethod(v, exprType.getSort() == Type.ARRAY ? OBJECT_TYPE : exprType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val z = 1;
|
||||||
|
return "O" + "K".toString() + z
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1 LDC "OK"
|
||||||
|
// 1 LDC
|
||||||
@@ -625,6 +625,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("partialString.kt")
|
||||||
|
public void testPartialString() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/partialString.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("short.kt")
|
@TestMetadata("short.kt")
|
||||||
public void testShort() throws Exception {
|
public void testShort() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/short.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/constants/short.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user