Attempting to use for+switch flow and compare it to current nested-for one. jbox2d seems to preform similarly well.
1.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Wed Mar 11 18:41:12 2015 +0100
1.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Apr 02 15:07:24 2015 +0200
1.3 @@ -466,10 +466,9 @@
1.4 } else {
1.5 didBranches = true;
1.6 lastStackFrame = -1;
1.7 - append("\n var gt = 0;\n");
1.8 + out.append("\n var gt = 0;\n for(;;) switch(gt) {\n");
1.9 }
1.10
1.11 - int openBraces = 0;
1.12 int topMostLabel = 0;
1.13 for (int i = 0; i < byteCodes.length; i++) {
1.14 int prev = i;
1.15 @@ -484,22 +483,10 @@
1.16 }
1.17 if (lastStackFrame != stackMapIterator.getFrameIndex()) {
1.18 smapper.flush(this);
1.19 - if (i != 0) {
1.20 - append(" }\n");
1.21 - }
1.22 - if (openBraces > 64) {
1.23 - for (int c = 0; c < 64; c++) {
1.24 - append("break;}\n");
1.25 - }
1.26 - openBraces = 1;
1.27 - topMostLabel = i;
1.28 - }
1.29 -
1.30 lastStackFrame = stackMapIterator.getFrameIndex();
1.31 lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals());
1.32 smapper.syncWithFrameStack(stackMapIterator.getFrameStack());
1.33 - append(" X_" + i).append(": for (;;) { IF: if (gt <= " + i + ") {\n");
1.34 - openBraces++;
1.35 + out.append(" case " + i).append(": ");
1.36 changeInCatch = true;
1.37 } else {
1.38 debug(" /* " + i + " */ ");
1.39 @@ -1513,9 +1500,6 @@
1.40 if (didBranches) {
1.41 append("\n }\n");
1.42 }
1.43 - while (openBraces-- > 0) {
1.44 - append('}');
1.45 - }
1.46 if (defineProp) {
1.47 append("\n}});");
1.48 } else {
1.49 @@ -2276,15 +2260,7 @@
1.50 }
1.51
1.52 private static void goTo(Appendable out, int current, int to, int canBack) throws IOException {
1.53 - if (to < current) {
1.54 - if (canBack < to) {
1.55 - out.append("{ gt = 0; continue X_" + to + "; }");
1.56 - } else {
1.57 - out.append("{ gt = " + to + "; continue X_0; }");
1.58 - }
1.59 - } else {
1.60 - out.append("{ gt = " + to + "; break IF; }");
1.61 - }
1.62 + out.append("{ gt = " + to + "; continue; }");
1.63 }
1.64
1.65 private static void emitIf(