Author: todd
Date: Fri May 27 18:58:14 2011
New Revision: 1128425
URL: http://svn.apache.org/viewvc?rev=1128425&view=rev
Log:
HADOOP-7333. Performance improvement in PureJavaCrc32. Contributed by Eric
Caspole.
Modified:
hadoop/common/trunk/CHANGES.txt
hadoop/common/trunk/src/java/org/apache/hadoop/util/PureJavaCrc32.java
Modified: hadoop/common/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1128425&r1=1128424&r2=1128425&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Fri May 27 18:58:14 2011
@@ -186,6 +186,9 @@ Trunk (unreleased changes)
(Harsh J Chouraria via todd)
OPTIMIZATIONS
+
+ HADOOP-7333. Performance improvement in PureJavaCrc32. (Eric Caspole
+ via todd)
BUG FIXES
Modified: hadoop/common/trunk/src/java/org/apache/hadoop/util/PureJavaCrc32.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/util/PureJavaCrc32.java?rev=1128425&r1=1128424&r2=1128425&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/util/PureJavaCrc32.java
(original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/util/PureJavaCrc32.java Fri
May 27 18:58:14 2011
@@ -57,23 +57,27 @@ public class PureJavaCrc32 implements Ch
/** {@inheritDoc} */
public void update(byte[] b, int off, int len) {
+ int localCrc = crc;
while(len > 7) {
- int c0 = b[off++] ^ crc;
- int c1 = b[off++] ^ (crc >>>= 8);
- int c2 = b[off++] ^ (crc >>>= 8);
- int c3 = b[off++] ^ (crc >>>= 8);
- crc = (T8_7[c0 & 0xff] ^ T8_6[c1 & 0xff])
+ int c0 = b[off++] ^ localCrc;
+ int c1 = b[off++] ^ (localCrc >>>= 8);
+ int c2 = b[off++] ^ (localCrc >>>= 8);
+ int c3 = b[off++] ^ (localCrc >>>= 8);
+ localCrc = (T8_7[c0 & 0xff] ^ T8_6[c1 & 0xff])
^ (T8_5[c2 & 0xff] ^ T8_4[c3 & 0xff]);
- crc ^= (T8_3[b[off++] & 0xff] ^ T8_2[b[off++] & 0xff])
+ localCrc ^= (T8_3[b[off++] & 0xff] ^ T8_2[b[off++] & 0xff])
^ (T8_1[b[off++] & 0xff] ^ T8_0[b[off++] & 0xff]);
len -= 8;
}
while(len > 0) {
- crc = (crc >>> 8) ^ T8_0[(crc ^ b[off++]) & 0xff];
+ localCrc = (localCrc >>> 8) ^ T8_0[(localCrc ^ b[off++]) & 0xff];
len--;
}
+
+ // Publish crc out to object
+ crc = localCrc;
}
/** {@inheritDoc} */