mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
Improve string concatentation & string templates code generation
Reuse StringBuilder instances for nested subexpressions.
(NB StringBuilder instance for string template with a string
concatenation inside an expression entry, such as `"${"a" + "b"}"`,
will not be reused, although that doesn't seem to be a real-life issue).
#KT-18558 Fixed Target versions 1.1.4
#KT-13682 Fixed Target versions 1.1.4
Join adjacent strings literals, escaped strings, and constant values
(in a language version that supports const val inlining).
Use StringBuilder#append(char) for single-character constants
(e.g., " " in "$a $b").
#KT-17280 Fixed Target versions 1.1.4
#KT-15235 Fixed Target versions 1.1.4
This commit is contained in:
4
compiler/testData/codegen/bytecodeText/stringOperations/kt15235.kt
vendored
Normal file
4
compiler/testData/codegen/bytecodeText/stringOperations/kt15235.kt
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
val c = 1
|
||||
fun foo() = "a\"($c)\"d"
|
||||
|
||||
// 3 INVOKEVIRTUAL java/lang/StringBuilder.append
|
||||
15
compiler/testData/codegen/bytecodeText/stringOperations/nestedConcat.kt
vendored
Normal file
15
compiler/testData/codegen/bytecodeText/stringOperations/nestedConcat.kt
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
fun test1(s1: String, s2: String, s3: String) =
|
||||
(s1 + s2) + s3
|
||||
|
||||
fun test2(s1: String, s2: String, s3: String) =
|
||||
s1 + (s2 + s3)
|
||||
|
||||
fun test3(s1: String, s2: String, s3: String, s4: String) =
|
||||
((s1 + s2) + ((s3 + s4)))
|
||||
|
||||
fun test4(s1: String, s2: String, s3: String) =
|
||||
"s1: $s1; " +
|
||||
"s2: $s2; " +
|
||||
"s3: $s3"
|
||||
|
||||
// 4 NEW java/lang/StringBuilder
|
||||
Reference in New Issue
Block a user