avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From th...@apache.org
Subject svn commit: r903266 - in /hadoop/avro/trunk: CHANGES.txt lang/java/src/java/org/apache/avro/io/BinaryDecoder.java
Date Tue, 26 Jan 2010 15:27:08 GMT
Author: thiru
Date: Tue Jan 26 15:27:07 2010
New Revision: 903266

URL: http://svn.apache.org/viewvc?rev=903266&view=rev
Log:
AVRO-354. Performance improvement to BinaryDecoder.readInt()

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/BinaryDecoder.java

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=903266&r1=903265&r2=903266&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Jan 26 15:27:07 2010
@@ -272,6 +272,8 @@
     AVRO-363. estSchema had two tests disabled; new test for named schemas 
     named after primitives. (philz)
 
+    AVRO-354. Performance improvement to BinaryDecoder.readInt() (Kevin Oliver via thiru)
+
   BUG FIXES
  
     AVRO-176. Safeguard against bad istreams before reading. (sbanacho)

Modified: hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/BinaryDecoder.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/BinaryDecoder.java?rev=903266&r1=903265&r2=903266&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/BinaryDecoder.java (original)
+++ hadoop/avro/trunk/lang/java/src/java/org/apache/avro/io/BinaryDecoder.java Tue Jan 26
15:27:07 2010
@@ -22,7 +22,6 @@
 import java.io.InputStream;
 import java.nio.ByteBuffer;
 
-import org.apache.avro.AvroTypeException;
 import org.apache.avro.ipc.ByteBufferInputStream;
 import org.apache.avro.util.Utf8;
 
@@ -105,11 +104,19 @@
 
   @Override
   public int readInt() throws IOException {
-    long result = readLong();
-    if (result < Integer.MIN_VALUE || Integer.MAX_VALUE < result) {
-      throw new AvroTypeException("Integer overflow.");
+    int n = 0;
+    for (int shift = 0; ; shift += 7) {
+      int b = in.read();
+      if (b >= 0) {
+         n |= (b & 0x7F) << shift;
+         if ((b & 0x80) == 0) {
+           break;
+         }
+      } else {
+        throw new EOFException();
+      }
     }
-    return (int)result;
+    return (n >>> 1) ^ -(n & 1); // back to two's-complement
   }
 
   @Override



Mime
View raw message