IR lowering for computing trimIndent/trimMargin on constants

This commit is contained in:
Jake Wharton
2019-04-20 00:33:34 -04:00
committed by max-kammerer
parent d765bebcfc
commit aaf533df16
4 changed files with 110 additions and 4 deletions
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
fun constant(): String {
return """
Hello,
@@ -17,6 +15,17 @@ fun interpolatedUsingConstant(): String {
""".trimIndent()
}
private const val SPACES = " "
private const val HELLO = "Hello"
private const val WORLD = "World"
fun reliesOnNestedStringBuilderFlatteningAndConstantConcatenation(): String {
return ("" + '\n' + SPACES + "${SPACES}Hey" + """
${HELLO + HELLO},
${WORLD + WORLD}
""" + SPACES).trimIndent()
}
// 1 LDC "Hello,\\nWorld"
// 1 LDC "Hello,\\nHello,\\nWorld\\nWorld"
// 1 LDC "Hey\\nHelloHello,\\nWorldWorld"
// 0 INVOKESTATIC kotlin/text/StringsKt.trimIndent
@@ -1,5 +1,3 @@
// IGNORE_BACKEND: JVM_IR
fun constant(): String {
return """
|Hello,
@@ -17,6 +15,17 @@ fun interpolatedUsingConstant(): String {
""".trimMargin()
}
private const val SPACES = " "
private const val HELLO = "Hello"
private const val WORLD = "World"
fun reliesOnNestedStringBuilderFlatteningAndConstantConcatenation(): String {
return ("" + '\n' + SPACES + "${SPACES}|Hey" + """
|${HELLO + HELLO},
|${WORLD + WORLD}
""" + SPACES).trimMargin()
}
fun constantCustomPrefix(): String {
return """
###Hello,
@@ -34,5 +43,6 @@ fun constantCustomPrefixInterpolatedUsingConstant(): String {
// 3 LDC "Hello,\\nWorld"
// 1 LDC "Hello,\\nHello,\\nWorld\\nWorld"
// 1 LDC "Hey\\nHelloHello,\\nWorldWorld"
// 0 LDC "###"
// 0 INVOKESTATIC kotlin/text/StringsKt.trimMargin