On Tuesday 22 February 2005 16:30, Oliver Jowett wrote:
> > I changed the line
> >
> > byte[][] answer = new byte[l_nf][0];
> > to
> > byte[][] answer = new byte[l_nf][];
> >
> > This gave ~1% increase on the benchmark I was running.
>
> Gah?! What JVM? Aren't the two forms equivalent?
javap says it's "multianewarray" vs. "anewarray":
| $ cat Test1.java
| public class Test1 {
| byte[][] answer = new byte[42][0];
| }
|
| $ cat Test2.java
| public class Test2 {
| byte[][] answer = new byte[42][];
| }
|
| $ javap -c -classpath . Test1
| Compiled from "Test1.java"
| public class Test1 extends java.lang.Object{
| byte[][] answer;
|
| public Test1();
| Code:
| 0: aload_0
| 1: invokespecial #1; //Method java/lang/Object."<init>":()V
| 4: aload_0
| 5: bipush 42
| 7: iconst_0
| 8: multianewarray #2, 2; //class "[[B"
| 12: putfield #3; //Field answer:[[B
| 15: return
|
| }
|
| $ javap -c -classpath . Test2
| Compiled from "Test2.java"
| public class Test2 extends java.lang.Object{
| byte[][] answer;
|
| public Test2();
| Code:
| 0: aload_0
| 1: invokespecial #1; //Method java/lang/Object."<init>":()V
| 4: aload_0
| 5: bipush 42
| 7: anewarray #2; //class "[B"
| 10: putfield #3; //Field answer:[[B
| 13: return
|
| }