rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java
branchclosure
changeset 1555 71e68f7ed23f
parent 1549 3f4c143ff8f0
child 1569 9eb0eb434c67
     1.1 --- a/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java	Wed May 07 16:47:24 2014 +0200
     1.2 +++ b/rt/emul/zip/src/main/java/org/apidesign/bck2brwsr/emul/zip/FastJar.java	Sun May 11 08:10:28 2014 +0200
     1.3 @@ -33,8 +33,10 @@
     1.4  import java.io.ByteArrayInputStream;
     1.5  import java.io.IOException;
     1.6  import java.io.InputStream;
     1.7 +import java.lang.reflect.Method;
     1.8  import java.util.zip.ZipEntry;
     1.9  import java.util.zip.ZipInputStream;
    1.10 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
    1.11  
    1.12  /**
    1.13   *
    1.14 @@ -100,7 +102,7 @@
    1.15          int giveup = 0;
    1.16  
    1.17          do {
    1.18 -            System.arraycopy(arr, at, data, 0, data.length);
    1.19 +            FastJar.arraycopy(arr, at, data, 0, data.length);
    1.20              at--;
    1.21              giveup++;
    1.22              if (giveup > GIVE_UP) {
    1.23 @@ -117,7 +119,7 @@
    1.24          int cenread = 0;
    1.25          data = new byte[ZipInputStream.CENHDR];
    1.26          while (cenread < censize) {
    1.27 -            System.arraycopy(arr, at, data, 0, data.length);
    1.28 +            FastJar.arraycopy(arr, at, data, 0, data.length);
    1.29              at += data.length;
    1.30              if (getsig(data) != ZipInputStream.CENSIG) {
    1.31                  throw new IOException("No central table");          //NOI18N
    1.32 @@ -141,7 +143,7 @@
    1.33      private Entry[] addEntry(Entry[] result, Entry entry) {
    1.34          Entry[] e = new Entry[result.length + 1];
    1.35          e[result.length] = entry;
    1.36 -        System.arraycopy(result, 0, e, 0, result.length);
    1.37 +        FastJar.arraycopy(result, 0, e, 0, result.length);
    1.38          return e;
    1.39      }
    1.40  
    1.41 @@ -171,5 +173,26 @@
    1.42  	final int s2 = get16(b, off+2);
    1.43          return s1 | ((long)s2 << 16);
    1.44      }
    1.45 +    
    1.46 +    @JavaScriptBody(args = {"value", "srcBegin", "dst", "dstBegin", "count"}, body
    1.47 +            = "if (srcBegin < dstBegin) {\n"
    1.48 +            + "    while (count-- > 0) {\n"
    1.49 +            + "        dst[dstBegin + count] = value[srcBegin + count];\n"
    1.50 +            + "    }\n"
    1.51 +            + "} else {\n"
    1.52 +            + "    while (count-- > 0) {\n"
    1.53 +            + "        dst[dstBegin++] = value[srcBegin++];\n"
    1.54 +            + "    }\n"
    1.55 +            + "}"
    1.56 +    )
    1.57 +    static void arraycopy(Object src, int srcBegin, Object dst, int dstBegin, int count) {
    1.58 +        try {
    1.59 +            Class<?> system = Class.forName("java.lang.System");
    1.60 +            Method m = system.getMethod("arraycopy", Object.class, int.class, Object.class, int.class, int.class);
    1.61 +            m.invoke(null, src, srcBegin, dst, dstBegin, count);
    1.62 +        } catch (Exception ex) {
    1.63 +            throw new IllegalStateException(ex);
    1.64 +        }
    1.65 +    }
    1.66  
    1.67  }