「文字列連結の最適化」の版間の差分
ナビゲーションに移動
検索に移動
1行目: | 1行目: | ||
==文字列連結の最適化== | ==文字列連結の最適化== | ||
− | + | [[http://www.y-adagio.com/public/standards/tr_javalang2/expressions.doc.html#40226 文字列の連結が最適化されているさま。]] | | |
/** | /** |
2020年2月15日 (土) 08:33時点における版
文字列連結の最適化
/** * @see JSL 15.18.1.2 Optimization of String Concatenation */ public class OptStrConcatTest { public static void main(String[] args) { String s2 = args[0] + args[1] + args[2]; } }
>javac OptStrConcatTest.java >javap -c SbTest > SbTest.jc
Compiled from "OptStrConcatTest.java" public class OptStrConcatTest extends java.lang.Object{ public OptStrConcatTest(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String[]); Code: 0: new #2; //class StringBuffer 3: dup 4: invokespecial #3; //Method java/lang/StringBuffer."<init>":()V 7: aload_0 8: iconst_0 9: aaload 10: invokevirtual #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer; 13: aload_0 14: iconst_1 15: aaload 16: invokevirtual #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer; 19: aload_0 20: iconst_2 21: aaload 22: invokevirtual #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer; 25: invokevirtual #5; //Method java/lang/StringBuffer.toString:()Ljava/lang/String; 28: astore_1 29: return }
© 2006 矢木浩人