Workaround of some problems with bytecode conversion demonstrated by ZipCompatibilityTest. Splitting the code into two new methods. emul
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 06 Feb 2013 15:47:06 +0100
branchemul
changeset 687a9e506a27b55
parent 686 63982243369c
child 690 8929a6558ae4
Workaround of some problems with bytecode conversion demonstrated by ZipCompatibilityTest. Splitting the code into two new methods.
emul/mini/src/main/java/java/util/zip/Inflater.java
     1.1 --- a/emul/mini/src/main/java/java/util/zip/Inflater.java	Wed Feb 06 15:22:57 2013 +0100
     1.2 +++ b/emul/mini/src/main/java/java/util/zip/Inflater.java	Wed Feb 06 15:47:06 2013 +0100
     1.3 @@ -882,23 +882,7 @@
     1.4          if (code != 65536)
     1.5            throw new DataFormatException("Code lengths don't add up properly.");
     1.6  
     1.7 -        /* Now create and fill the extra tables from longest to shortest
     1.8 -         * bit len.  This way the sub trees will be aligned.
     1.9 -         */
    1.10 -        tree = new short[treeSize];
    1.11 -        int treePtr = 512;
    1.12 -        for (int bits = MAX_BITLEN; bits >= 10; bits--)
    1.13 -          {
    1.14 -        int end   = code & 0x1ff80;
    1.15 -        code -= blCount[bits] << (16 - bits);
    1.16 -        int start = code & 0x1ff80;
    1.17 -        for (int i = start; i < end; i += 1 << 7)
    1.18 -          {
    1.19 -            tree[bitReverse(i)]
    1.20 -              = (short) ((-treePtr << 4) | bits);
    1.21 -            treePtr += 1 << (bits-9);
    1.22 -          }
    1.23 -          }
    1.24 +        fillTable1(treeSize, code, blCount);
    1.25  
    1.26          for (int i = 0; i < codeLengths.length; i++)
    1.27            {
    1.28 @@ -935,11 +919,11 @@
    1.29          "\000\010\004\014\002\012\006\016\001\011\005\015\003\013\007\017";
    1.30        static short bitReverse(int value) {
    1.31              return (short) (bit4Reverse.charAt(value & 0xf) << 12
    1.32 -                | bit4Reverse.charAt((value >> 4) & 0xf) << 8
    1.33 -                | bit4Reverse.charAt((value >> 8) & 0xf) << 4
    1.34 -                | bit4Reverse.charAt(value >> 12));
    1.35 +                    | bit4Reverse.charAt((value >> 4) & 0xf) << 8
    1.36 +                    | bit4Reverse.charAt((value >> 8) & 0xf) << 4
    1.37 +                    | bit4Reverse.charAt(value >> 12));
    1.38        }
    1.39 -
    1.40 +      
    1.41        /**
    1.42         * Reads the next symbol from input.  The symbol is encoded using the
    1.43         * huffman tree.
    1.44 @@ -992,6 +976,29 @@
    1.45            return -1;
    1.46            }
    1.47        }
    1.48 +
    1.49 +        private void fillTable1(int treeSize, int code, int[] blCount) {
    1.50 +            /* Now create and fill the extra tables from longest to shortest
    1.51 +             * bit len.  This way the sub trees will be aligned.
    1.52 +             */
    1.53 +            tree = new short[treeSize];
    1.54 +            int treePtr = 512;
    1.55 +            for (int bits = MAX_BITLEN; bits >= 10; bits--) {
    1.56 +                int end = code & 0x1ff80;
    1.57 +                code -= blCount[bits] << (16 - bits);
    1.58 +                int start = code & 0x1ff80;
    1.59 +                final int inc = 1 << 7;
    1.60 +                fillTable2(start, end, inc, treePtr, bits);
    1.61 +            }
    1.62 +        }
    1.63 +
    1.64 +        private void fillTable2(int start, int end, final int inc, int treePtr, int bits) {
    1.65 +            for (int i = start; i < end; i += inc) {
    1.66 +                final short br = bitReverse(i);
    1.67 +                tree[br] = (short) ((-treePtr << 4) | bits);
    1.68 +                treePtr += 1 << (bits - 9);
    1.69 +            }
    1.70 +        }
    1.71      }
    1.72      private static class InflaterDynHeader
    1.73      {