ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexey Panchenko <alex+n...@olmisoft.com>
Subject Re[2]: AW: Adding a methof to StringUtils
Date Wed, 19 Apr 2006 10:38:48 GMT
Kev Jackson wrote:

> It's less to do with speed performance and more to do with memory
> performance.  "a" + "b" + "c" creates "a" + "bc" <- intermediate String, 
> and then "abc"

Many years ago - yes, but not now.


java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

public class AAA {
  public String concat(String a, String b, String c) {
    return a + b + c;
  }
}

javac AAA.java

javap -c AAA

public java.lang.String concat(java.lang.String, java.lang.String, java.lang.String);
  Code:
   0:   new     #2; //class java/lang/StringBuilder
   3:   dup
   4:   invokespecial   #3; //Method java/lang/StringBuilder."<init>":()V
   7:   aload_1
   8:   invokevirtual   #4; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   11:  aload_2
   12:  invokevirtual   #4; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   15:  aload_3
   16:  invokevirtual   #4; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
   19:  invokevirtual   #5; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
   22:  areturn

javac -source 1.4 -target 1.4 AAA.java

javap -c AAA

public java.lang.String concat(java.lang.String, java.lang.String, java.lang.String);
  Code:
   0:   new     #2; //class java/lang/StringBuffer
   3:   dup
   4:   invokespecial   #3; //Method java/lang/StringBuffer."<init>":()V
   7:   aload_1
   8:   invokevirtual   #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
   11:  aload_2
   12:  invokevirtual   #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
   15:  aload_3
   16:  invokevirtual   #4; //Method java/lang/StringBuffer.append:(Ljava/lang/String;)Ljava/lang/StringBuffer;
   19:  invokevirtual   #5; //Method java/lang/StringBuffer.toString:()Ljava/lang/String;
   22:  areturn

-- 
Best regards,
 Alexey                            mailto:alex+news@olmisoft.com


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message