commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1340790 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/compressors/bzip2/ test/java/org/apache/commons/compress/compressors/bzip2/
Date Sun, 20 May 2012 18:10:46 GMT
Author: bodewig
Date: Sun May 20 18:10:46 2012
New Revision: 1340790

URL: http://svn.apache.org/viewvc?rev=1340790&view=rev
Log:
remove randomization code

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/bzip2/BlockSortTest.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java?rev=1340790&r1=1340789&r2=1340790&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
Sun May 20 18:10:46 2012
@@ -562,7 +562,7 @@ public class BZip2CompressorOutputStream
         }
 
         /* sort the block and establish posn of original string */
-        final boolean blockRandomised = blockSort();
+        blockSort();
 
         /*
          * A 6-byte block header, the value chosen arbitrarily as 0x314159265359
@@ -585,12 +585,8 @@ public class BZip2CompressorOutputStream
         /* Now the block's CRC, so it is in a known place. */
         bsPutInt(this.blockCRC);
 
-        /* Now a single bit indicating randomisation. */
-        if (blockRandomised) {
-            bsW(1, 1);
-        } else {
-            bsW(1, 0);
-        }
+        /* Now a single bit indicating no randomisation. */
+        bsW(1, 0);
 
         /* Finally, block's contents proper. */
         moveToFrontCodeAndSend();
@@ -1165,8 +1161,8 @@ public class BZip2CompressorOutputStream
         sendMTFValues();
     }
 
-    private boolean blockSort() {
-        return blockSorter.blockSort(data, last);
+    private void blockSort() {
+        blockSorter.blockSort(data, last);
     }
 
     /*

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java?rev=1340790&r1=1340789&r2=1340790&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BlockSort.java
Sun May 20 18:10:46 2012
@@ -98,12 +98,13 @@ class BlockSort {
      * This class seems to mix several revisions of libbzip2's code.
      * The mainSort function and those used by it look closer to the
      * 0.9.5 version but show some variations introduced later.  At
-     * the same time the logic to randomize the block on bad input has
-     * been dropped after 0.9.0 and replaced by a fallback sorting
-     * algorithm.
+     * the same time the logic of Compress 1.4 to randomize the block
+     * on bad input has been dropped after libbzip2 0.9.0 and replaced
+     * by a fallback sorting algorithm.
      *
      * I've added the fallbackSort function of 1.0.6 and tried to
      * integrate it with the existing code without touching too much.
+     * I've also removed the now unused reandomization code.
      */
 
     /*
@@ -120,11 +121,9 @@ class BlockSort {
         QSORT_STACK_SIZE < FALLBACK_QSORT_STACK_SIZE
         ? FALLBACK_QSORT_STACK_SIZE : QSORT_STACK_SIZE;
 
-    private boolean blockRandomised;
-
     /*
      * Used when sorting. If too many long comparisons happen, we stop sorting,
-     * randomise the block slightly, and try again.
+     * and use fallbackSort instead.
      */
     private int workDone;
     private int workLimit;
@@ -151,10 +150,9 @@ class BlockSort {
         this.quadrant = data.sfmap;
     }
 
-    boolean blockSort(final BZip2CompressorOutputStream.Data data, final int last) {
+    void blockSort(final BZip2CompressorOutputStream.Data data, final int last) {
         this.workLimit = WORK_FACTOR * last;
         this.workDone = 0;
-        this.blockRandomised = false;
         this.firstAttempt = true;
 
         if (last + 1 < 10000) {
@@ -177,7 +175,6 @@ class BlockSort {
         }
 
         // assert (data.origPtr != -1) : data.origPtr;
-        return false;
     }
 
     /**
@@ -1057,35 +1054,4 @@ class BlockSort {
         }
     }
 
-/*---------------------------------------------*/
-
-    private void randomiseBlock(final BZip2CompressorOutputStream.Data data,
-                                final int lastShadow) {
-        final boolean[] inUse = data.inUse;
-        final byte[] block = data.block;
-
-        for (int i = 256; --i >= 0;) {
-            inUse[i] = false;
-        }
-
-        int rNToGo = 0;
-        int rTPos = 0;
-        for (int i = 0, j = 1; i <= lastShadow; i = j, j++) {
-            if (rNToGo == 0) {
-                rNToGo = (char) Rand.rNums(rTPos);
-                if (++rTPos == 512) {
-                    rTPos = 0;
-                }
-            }
-
-            rNToGo--;
-            block[j] ^= ((rNToGo == 1) ? 1 : 0);
-
-            // handle 16 bit signed numbers
-            inUse[block[j] & 0xff] = true;
-        }
-
-        this.blockRandomised = true;
-    }
-
 }

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/bzip2/BlockSortTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/bzip2/BlockSortTest.java?rev=1340790&r1=1340789&r2=1340790&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/bzip2/BlockSortTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/bzip2/BlockSortTest.java
Sun May 20 18:10:46 2012
@@ -22,7 +22,6 @@ import org.junit.Test;
 
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 
 public class BlockSortTest {
 
@@ -81,7 +80,7 @@ public class BlockSortTest {
     @Test
     public void testSortFixture() {
         DS ds = setUpFixture();
-        assertFalse(ds.s.blockSort(ds.data, FIXTURE.length - 1));
+        ds.s.blockSort(ds.data, FIXTURE.length - 1);
         assertFixtureSorted(ds.data);
         assertEquals(0, ds.data.origPtr);
     }
@@ -103,7 +102,7 @@ public class BlockSortTest {
     @Test
     public void testSortFixture2() {
         DS ds = setUpFixture2();
-        assertFalse(ds.s.blockSort(ds.data, FIXTURE2.length - 1));
+        ds.s.blockSort(ds.data, FIXTURE2.length - 1);
         assertFixture2Sorted(ds.data);
         assertEquals(1, ds.data.origPtr);
     }



Mime
View raw message