# HG changeset patch # User Jaroslav Tulach # Date 1399788628 -7200 # Node ID 71e68f7ed23f56173e18d7c66517509a2d13606f # Parent 7ba27baf5f3f3fa79493556b0f66dad9c6b9d228 Use as little of Java APIs as possible diff -r 7ba27baf5f3f -r 71e68f7ed23f rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java --- a/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java Sun May 11 08:08:17 2014 +0200 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/CRC32.java Sun May 11 08:10:28 2014 +0200 @@ -175,7 +175,7 @@ public static int[] getCRC32Table(){ int[] tmp = new int[crc_table.length]; - System.arraycopy(crc_table, 0, tmp, 0, tmp.length); + FastJar.arraycopy(crc_table, 0, tmp, 0, tmp.length); return tmp; } } diff -r 7ba27baf5f3f -r 71e68f7ed23f rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java --- a/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java Sun May 11 08:08:17 2014 +0200 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java Sun May 11 08:10:28 2014 +0200 @@ -33,8 +33,10 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Method; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import org.apidesign.bck2brwsr.core.JavaScriptBody; /** * @@ -100,7 +102,7 @@ int giveup = 0; do { - System.arraycopy(arr, at, data, 0, data.length); + FastJar.arraycopy(arr, at, data, 0, data.length); at--; giveup++; if (giveup > GIVE_UP) { @@ -117,7 +119,7 @@ int cenread = 0; data = new byte[ZipInputStream.CENHDR]; while (cenread < censize) { - System.arraycopy(arr, at, data, 0, data.length); + FastJar.arraycopy(arr, at, data, 0, data.length); at += data.length; if (getsig(data) != ZipInputStream.CENSIG) { throw new IOException("No central table"); //NOI18N @@ -141,7 +143,7 @@ private Entry[] addEntry(Entry[] result, Entry entry) { Entry[] e = new Entry[result.length + 1]; e[result.length] = entry; - System.arraycopy(result, 0, e, 0, result.length); + FastJar.arraycopy(result, 0, e, 0, result.length); return e; } @@ -171,5 +173,26 @@ final int s2 = get16(b, off+2); return s1 | ((long)s2 << 16); } + + @JavaScriptBody(args = {"value", "srcBegin", "dst", "dstBegin", "count"}, body + = "if (srcBegin < dstBegin) {\n" + + " while (count-- > 0) {\n" + + " dst[dstBegin + count] = value[srcBegin + count];\n" + + " }\n" + + "} else {\n" + + " while (count-- > 0) {\n" + + " dst[dstBegin++] = value[srcBegin++];\n" + + " }\n" + + "}" + ) + static void arraycopy(Object src, int srcBegin, Object dst, int dstBegin, int count) { + try { + Class system = Class.forName("java.lang.System"); + Method m = system.getMethod("arraycopy", Object.class, int.class, Object.class, int.class, int.class); + m.invoke(null, src, srcBegin, dst, dstBegin, count); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } } diff -r 7ba27baf5f3f -r 71e68f7ed23f rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java --- a/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java Sun May 11 08:08:17 2014 +0200 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/GZIPHeader.java Sun May 11 08:10:28 2014 +0200 @@ -194,19 +194,19 @@ byte[] tmp; if(gheader.extra!=null){ tmp=new byte[gheader.extra.length]; - System.arraycopy(gheader.extra, 0, tmp, 0, tmp.length); + FastJar.arraycopy(gheader.extra, 0, tmp, 0, tmp.length); gheader.extra = tmp; } if(gheader.name!=null){ tmp=new byte[gheader.name.length]; - System.arraycopy(gheader.name, 0, tmp, 0, tmp.length); + FastJar.arraycopy(gheader.name, 0, tmp, 0, tmp.length); gheader.name = tmp; } if(gheader.comment!=null){ tmp=new byte[gheader.comment.length]; - System.arraycopy(gheader.comment, 0, tmp, 0, tmp.length); + FastJar.arraycopy(gheader.comment, 0, tmp, 0, tmp.length); gheader.comment = tmp; } diff -r 7ba27baf5f3f -r 71e68f7ed23f rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java --- a/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java Sun May 11 08:08:17 2014 +0200 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfBlocks.java Sun May 11 08:10:28 2014 +0200 @@ -270,7 +270,7 @@ t = left; if(t>n) t = n; if(t>m) t = m; - System.arraycopy(z.next_in, p, window, q, t); + FastJar.arraycopy(z.next_in, p, window, q, t); p += t; n -= t; q += t; m -= t; if ((left -= t) != 0) @@ -540,7 +540,7 @@ } void set_dictionary(byte[] d, int start, int n){ - System.arraycopy(d, start, window, 0, n); + FastJar.arraycopy(d, start, window, 0, n); read = write = n; } @@ -575,7 +575,7 @@ } // copy as far as end of window - System.arraycopy(window, q, z.next_out, p, n); + FastJar.arraycopy(window, q, z.next_out, p, n); p += n; q += n; @@ -601,7 +601,7 @@ } // copy - System.arraycopy(window, q, z.next_out, p, n); + FastJar.arraycopy(window, q, z.next_out, p, n); p += n; q += n; } diff -r 7ba27baf5f3f -r 71e68f7ed23f rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfCodes.java --- a/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfCodes.java Sun May 11 08:08:17 2014 +0200 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfCodes.java Sun May 11 08:10:28 2014 +0200 @@ -503,7 +503,7 @@ c-=2; } else{ - System.arraycopy(s.window, r, s.window, q, 2); + FastJar.arraycopy(s.window, r, s.window, q, 2); q+=2; r+=2; c-=2; } } @@ -520,7 +520,7 @@ while(--e!=0); } else{ - System.arraycopy(s.window, r, s.window, q, e); + FastJar.arraycopy(s.window, r, s.window, q, e); q+=e; r+=e; e=0; } r = 0; // copy rest from start of window @@ -534,7 +534,7 @@ while(--c!=0); } else{ - System.arraycopy(s.window, r, s.window, q, c); + FastJar.arraycopy(s.window, r, s.window, q, c); q+=c; r+=c; c=0; } break; diff -r 7ba27baf5f3f -r 71e68f7ed23f rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfTree.java --- a/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfTree.java Sun May 11 08:08:17 2014 +0200 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/InfTree.java Sun May 11 08:10:28 2014 +0200 @@ -372,7 +372,7 @@ r[1]=(byte)l; // bits to dump before this table j=i>>>(w - l); r[2] = (int)(q - u[h-1] - j); // offset to this table - System.arraycopy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table + FastJar.arraycopy(r, 0, hp, (u[h-1]+j)*3, 3); // connect to last table } else{ t[0] = q; // first table is returned result @@ -396,7 +396,7 @@ // fill code-like entries with r f=1<<(k-w); for (j=i>>>w;j0 && append){ byte[] tmp = new byte[avail_in+len]; - System.arraycopy(next_in, next_in_index, tmp, 0, avail_in); - System.arraycopy(buf, off, tmp, avail_in, len); + FastJar.arraycopy(next_in, next_in_index, tmp, 0, avail_in); + FastJar.arraycopy(buf, off, tmp, avail_in, len); next_in=tmp; next_in_index=0; avail_in+=len; diff -r 7ba27baf5f3f -r 71e68f7ed23f rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/vmzip/ZipResources.java --- a/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/vmzip/ZipResources.java Sun May 11 08:08:17 2014 +0200 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/vmzip/ZipResources.java Sun May 11 08:10:28 2014 +0200 @@ -54,7 +54,7 @@ private byte[] findRes(String res) throws IOException { Object arr = findResImpl(res); if (arr instanceof FastJar.Entry) { - long bef = timeNow(); + double bef = timeNow(); InputStream zip = fj.getInputStream((FastJar.Entry)arr); arr = readFully(new byte[512], zip); putRes(res, arr); @@ -97,19 +97,12 @@ return arr; } - private static long timeNow() { - double time = m(); - if (time >= 0) { - return (long)time; - } - return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis(); - } @JavaScriptBody(args = {}, body = "if (typeof window.performance === 'undefined') return -1;\n" + "if (typeof window.performance.now === 'undefined') return -1;\n" + "return window.performance.now();" ) - private static native double m(); + private static native double timeNow(); } diff -r 7ba27baf5f3f -r 71e68f7ed23f rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java --- a/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java Sun May 11 08:08:17 2014 +0200 +++ b/rt/emul/zip/src/test/java/org/apidesign/bck2brwsr/vmtest/impl/ZipFileTest.java Sun May 11 08:10:28 2014 +0200 @@ -19,7 +19,6 @@ import java.io.IOException; import java.io.InputStream; -import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.apidesign.bck2brwsr.core.JavaScriptBody; @@ -99,7 +98,16 @@ } private static void assertEquals(Object real, Object exp, String msg) { - assert Objects.equals(exp, real) : msg + " exp: " + exp + " real: " + real; + if (real == null) { + if (exp == null) { + return; + } + } else { + if (real.equals(exp)) { + return; + } + } + assert false : msg + " exp: " + exp + " real: " + real; } @Factory public static Object[] create() {