# HG changeset patch # User Jaroslav Tulach # Date 1427980044 -7200 # Node ID 33ef5fe79475c2de7d98201e704555e7ed010848 # Parent ff2a253900ed154e7403db87b8770c0f728e064d Attempting to use for+switch flow and compare it to current nested-for one. jbox2d seems to preform similarly well. diff -r ff2a253900ed -r 33ef5fe79475 rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Wed Mar 11 18:41:12 2015 +0100 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Apr 02 15:07:24 2015 +0200 @@ -466,10 +466,9 @@ } else { didBranches = true; lastStackFrame = -1; - append("\n var gt = 0;\n"); + out.append("\n var gt = 0;\n for(;;) switch(gt) {\n"); } - int openBraces = 0; int topMostLabel = 0; for (int i = 0; i < byteCodes.length; i++) { int prev = i; @@ -484,22 +483,10 @@ } if (lastStackFrame != stackMapIterator.getFrameIndex()) { smapper.flush(this); - if (i != 0) { - append(" }\n"); - } - if (openBraces > 64) { - for (int c = 0; c < 64; c++) { - append("break;}\n"); - } - openBraces = 1; - topMostLabel = i; - } - lastStackFrame = stackMapIterator.getFrameIndex(); lmapper.syncWithFrameLocals(stackMapIterator.getFrameLocals()); smapper.syncWithFrameStack(stackMapIterator.getFrameStack()); - append(" X_" + i).append(": for (;;) { IF: if (gt <= " + i + ") {\n"); - openBraces++; + out.append(" case " + i).append(": "); changeInCatch = true; } else { debug(" /* " + i + " */ "); @@ -1513,9 +1500,6 @@ if (didBranches) { append("\n }\n"); } - while (openBraces-- > 0) { - append('}'); - } if (defineProp) { append("\n}});"); } else { @@ -2276,15 +2260,7 @@ } private static void goTo(Appendable out, int current, int to, int canBack) throws IOException { - if (to < current) { - if (canBack < to) { - out.append("{ gt = 0; continue X_" + to + "; }"); - } else { - out.append("{ gt = " + to + "; continue X_0; }"); - } - } else { - out.append("{ gt = " + to + "; break IF; }"); - } + out.append("{ gt = " + to + "; continue; }"); } private static void emitIf(