Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions hadoop-hdds/common/dev-support/findbugsExcludeFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,4 @@
<Class name="org.apache.hadoop.ozone.OzoneConsts"/>
<Bug pattern="DMI_HARDCODED_ABSOLUTE_FILENAME" />
</Match>
<Match>
<Class name="org.apache.hadoop.ozone.common.ChecksumByteBuffer$CrcIntTable" />
<Method name="update" />
<Bug pattern="SF_SWITCH_FALLTHROUGH,SF_SWITCH_NO_DEFAULT" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
* limitations under the License.
*/

/*
* Some portions of this file Copyright (c) 2004-2006 Intel Corporation and licensed under the BSD license.
*/

package org.apache.hadoop.ozone.common;

import java.nio.ByteBuffer;
import java.util.zip.Checksum;
import org.apache.ratis.util.Preconditions;

/**
* A sub-interface of {@link Checksum}
Expand All @@ -47,81 +42,4 @@ public interface ChecksumByteBuffer extends Checksum {
default void update(byte[] b, int off, int len) {
update(ByteBuffer.wrap(b, off, len).asReadOnlyBuffer());
}

/**
* An abstract class implementing {@link ChecksumByteBuffer}
* with a 32-bit checksum and a lookup table.
*/
@SuppressWarnings("innerassignment")
abstract class CrcIntTable implements ChecksumByteBuffer {
/** Current CRC value with bit-flipped. */
private int crc;

CrcIntTable() {
reset();
Preconditions.assertTrue(getTable().length == 8 * (1 << 8));
}

abstract int[] getTable();

@Override
public final long getValue() {
return (~crc) & 0xffffffffL;
}

@Override
public final void reset() {
crc = 0xffffffff;
}

@Override
public final void update(int b) {
crc = (crc >>> 8) ^ getTable()[(((crc ^ b) << 24) >>> 24)];
}

@Override
public final void update(ByteBuffer b) {
crc = update(crc, b, getTable());
}

private static int update(int crc, ByteBuffer b, int[] table) {
for (; b.remaining() > 7;) {
final int c0 = (b.get() ^ crc) & 0xff;
final int c1 = (b.get() ^ (crc >>>= 8)) & 0xff;
final int c2 = (b.get() ^ (crc >>>= 8)) & 0xff;
final int c3 = (b.get() ^ (crc >>> 8)) & 0xff;
crc = (table[0x700 + c0] ^ table[0x600 + c1])
^ (table[0x500 + c2] ^ table[0x400 + c3]);

final int c4 = b.get() & 0xff;
final int c5 = b.get() & 0xff;
final int c6 = b.get() & 0xff;
final int c7 = b.get() & 0xff;

crc ^= (table[0x300 + c4] ^ table[0x200 + c5])
^ (table[0x100 + c6] ^ table[c7]);
}

// loop unroll - duff's device style
switch (b.remaining()) {
case 7:
crc = (crc >>> 8) ^ table[((crc ^ b.get()) & 0xff)];
case 6:
crc = (crc >>> 8) ^ table[((crc ^ b.get()) & 0xff)];
case 5:
crc = (crc >>> 8) ^ table[((crc ^ b.get()) & 0xff)];
case 4:
crc = (crc >>> 8) ^ table[((crc ^ b.get()) & 0xff)];
case 3:
crc = (crc >>> 8) ^ table[((crc ^ b.get()) & 0xff)];
case 2:
crc = (crc >>> 8) ^ table[((crc ^ b.get()) & 0xff)];
case 1:
crc = (crc >>> 8) ^ table[((crc ^ b.get()) & 0xff)];
default: // noop
}

return crc;
}
}
}
Loading