Skip to content

Instantly share code, notes, and snippets.

@jrenner
Created October 12, 2014 14:00
Show Gist options
  • Save jrenner/e074d009614df27fd950 to your computer and use it in GitHub Desktop.
Save jrenner/e074d009614df27fd950 to your computer and use it in GitHub Desktop.
testing kotlin string concatenation bytecode results
fun test() {
val x = "a" + "b" + "c"
}
fun test2() {
val sb = StringBuilder()
sb.append("a").append("b").append("c")
val x = sb.toString()
}
fun test3() {
val a = "a"
val b = "b"
val c = "c"
val x = "$a $b $c"
}
////////////////// bytecode
public final static test()V
L0
L1
L2
L3
LINENUMBER 63 L3
NEW java/lang/StringBuilder
DUP
INVOKESPECIAL java/lang/StringBuilder.<init> ()V
LDC "a"
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
LDC "b"
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
LDC "c"
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
ASTORE 0
L4
LOCALVARIABLE x Ljava/lang/String; L2 L4 0
RETURN
L5
MAXSTACK = -1
MAXLOCALS = -1
// access flags 0x19
public final static test2()V
L0
L1
L2
L3
LINENUMBER 67 L3
NEW java/lang/StringBuilder
DUP
INVOKESPECIAL java/lang/StringBuilder.<init> ()V
ASTORE 0
L4
LINENUMBER 68 L4
ALOAD 0
LDC "a"
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
DUP
LDC "StringBuilder"
LDC "append"
INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkReturnedValueIsNotNull (Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V
LDC "b"
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
DUP
LDC "StringBuilder"
LDC "append"
INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkReturnedValueIsNotNull (Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V
LDC "c"
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
DUP
LDC "StringBuilder"
LDC "append"
INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkReturnedValueIsNotNull (Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V
POP
L5
L6
LINENUMBER 69 L6
ALOAD 0
INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
DUP
LDC "StringBuilder"
LDC "toString"
INVOKESTATIC kotlin/jvm/internal/Intrinsics.checkReturnedValueIsNotNull (Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V
ASTORE 1
L7
LOCALVARIABLE x Ljava/lang/String; L5 L7 1
LOCALVARIABLE sb Ljava/lang/StringBuilder; L2 L7 0
RETURN
L8
MAXSTACK = -1
MAXLOCALS = -1
// access flags 0x19
public final static test3()V
L0
L1
L2
L3
LINENUMBER 73 L3
LDC "a"
ASTORE 0
L4
L5
LINENUMBER 74 L5
LDC "b"
ASTORE 1
L6
L7
LINENUMBER 75 L7
LDC "c"
ASTORE 2
L8
L9
LINENUMBER 76 L9
NEW java/lang/StringBuilder
DUP
INVOKESPECIAL java/lang/StringBuilder.<init> ()V
ALOAD 0
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
LDC " "
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
ALOAD 1
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
LDC " "
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
ALOAD 2
INVOKEVIRTUAL java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;
INVOKEVIRTUAL java/lang/StringBuilder.toString ()Ljava/lang/String;
ASTORE 3
L10
LOCALVARIABLE x Ljava/lang/String; L8 L10 3
LOCALVARIABLE c Ljava/lang/String; L6 L10 2
LOCALVARIABLE b Ljava/lang/String; L4 L10 1
LOCALVARIABLE a Ljava/lang/String; L2 L10 0
RETURN
L11
MAXSTACK = -1
MAXLOCALS = -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment