avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1442391 - in /avro/trunk: CHANGES.txt lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java
Date Mon, 04 Feb 2013 21:58:45 GMT
Author: cutting
Date: Mon Feb  4 21:58:45 2013
New Revision: 1442391

URL: http://svn.apache.org/viewvc?rev=1442391&view=rev
Log:
AVRO-1241. Java: Optimize Trevni string input.  Contributed by Joseph Adler.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1442391&r1=1442390&r2=1442391&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Mon Feb  4 21:58:45 2013
@@ -25,6 +25,8 @@ Trunk (not yet released)
     AVRO-1232. Java: Add a toString() method to AvroWrapper so that it
     works with TextOutputFormat.  (Garrett Wu via cutting)
 
+    AVRO-1241. Java: Optimize Trevni string input. (Joseph Adler via cutting)
+
   BUG FIXES
 
     AVRO-1231. Java: Fix Trevni shredder to work on non-recursive

Modified: avro/trunk/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java?rev=1442391&r1=1442390&r2=1442391&view=diff
==============================================================================
--- avro/trunk/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java (original)
+++ avro/trunk/lang/java/trevni/core/src/main/java/org/apache/trevni/InputBuffer.java Mon
Feb  4 21:58:45 2013
@@ -21,6 +21,7 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
 
 /** Used to read values. */
 class InputBuffer {
@@ -33,6 +34,8 @@ class InputBuffer {
   private int pos;                                // position within buffer
   private int limit;                              // end of valid buffer data
 
+  private CharsetDecoder utf8 = Charset.forName("UTF-8").newDecoder();
+  
   private int bitCount;                           // position in booleans
 
   public InputBuffer(Input in) throws IOException { this(in, 0); }
@@ -274,18 +277,16 @@ class InputBuffer {
     return (readFixed32() & 0xFFFFFFFFL) | (((long)readFixed32()) << 32);
   }
 
-  private static final Charset UTF8 = Charset.forName("UTF-8");
-
   public String readString() throws IOException {
     int length = readInt();
     if (length <= (limit - pos)) {                        // in buffer
-      String result = new String(buf, pos, length, UTF8); // read directly
+      String result = utf8.decode(ByteBuffer.wrap(buf, pos, length)).toString();
       pos += length;
       return result;
     }
     byte[] bytes = new byte[length];
     readFully(bytes, 0, length);
-    return new String(bytes, 0, length, UTF8);
+    return utf8.decode(ByteBuffer.wrap(bytes, 0, length)).toString();
   }  
 
   public byte[] readBytes() throws IOException {



Mime
View raw message