| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

「文字列連結の最適化」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
 
1行目: 1行目:
==文字列連結の最適化==
+
==[[文字列連結の最適化]]==
  
[[http://www.y-adagio.com/public/standards/tr_javalang2/expressions.doc.html#40226 文字列の連結が最適化されているさま。]] |
+
[http://www.y-adagio.com/public/standards/tr_javalang2/expressions.doc.html#40226 文字列の連結が最適化されているさま。]
  
 
  /**
 
  /**
33行目: 33行目:
 
     8: iconst_0
 
     8: iconst_0
 
     9: aaload
 
     9: aaload
     10: invokevirtual #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
+
     10: invoke[[vi]]rtual #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
 
     13: aload_0
 
     13: aload_0
 
     14: iconst_1
 
     14: iconst_1
 
     15: aaload
 
     15: aaload
     16: invokevirtual #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
+
     16: invoke[[vi]]rtual #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
 
     19: aload_0
 
     19: aload_0
 
     20: iconst_2
 
     20: iconst_2
 
     21: aaload
 
     21: aaload
     22: invokevirtual #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
+
     22: invoke[[vi]]rtual #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
     25: invokevirtual #5; //Method java/lang/StringBuffer.toString:()Ljava/lang/String;
+
     25: invoke[[vi]]rtual #5; //Method java/lang/StringBuffer.toString:()Ljava/lang/String;
 
     28: astore_1
 
     28: astore_1
 
     29: return
 
     29: return
48行目: 48行目:
  
 
----
 
----
{{include_html banner_html, "!Java"}}
+
{{include_html [[banner_html]], "!Java"}}

2020年2月16日 (日) 04:21時点における最新版

文字列連結の最適化

文字列の連結が最適化されているさま。

/**
 * @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
}

{{include_html banner_html, "!Java"}}