Bläddra i källkod

HADOOP-6109. Change Text to grow its internal buffer exponentially, rather
than the max of the current length and the proposed length to improve
performance reading large values. Contributed by thushara wijeratna


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@789242 13f79535-47bb-0310-9956-ffa450edef68

Christopher Douglas 16 år sedan
förälder
incheckning
e93ebeae51
2 ändrade filer med 8 tillägg och 3 borttagningar
  1. 4 0
      CHANGES.txt
  2. 4 3
      src/java/org/apache/hadoop/io/Text.java

+ 4 - 0
CHANGES.txt

@@ -464,6 +464,10 @@ Trunk (unreleased changes)
 
     HADOOP-5925. EC2 scripts should exit on error. (tomwhite)
 
+    HADOOP-6109. Change Text to grow its internal buffer exponentially, rather
+    than the max of the current length and the proposed length to improve
+    performance reading large values. (thushara wijeratna via cdouglas)
+
   OPTIMIZATIONS
 
     HADOOP-5595. NameNode does not need to run a replicator to choose a

+ 4 - 3
src/java/org/apache/hadoop/io/Text.java

@@ -31,6 +31,7 @@ import java.nio.charset.CodingErrorAction;
 import java.nio.charset.MalformedInputException;
 import java.text.CharacterIterator;
 import java.text.StringCharacterIterator;
+import java.util.Arrays;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -237,11 +238,11 @@ public class Text extends BinaryComparable
    */
   private void setCapacity(int len, boolean keepData) {
     if (bytes == null || bytes.length < len) {
-      byte[] newBytes = new byte[len];
       if (bytes != null && keepData) {
-        System.arraycopy(bytes, 0, newBytes, 0, length);
+        bytes = Arrays.copyOf(bytes, Math.max(len,length << 1));
+      } else {
+        bytes = new byte[len];
       }
-      bytes = newBytes;
     }
   }