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
This commit is contained in:
Christopher Douglas 2009-06-29 07:16:56 +00:00
parent 1d6d98c9fb
commit e93ebeae51
2 changed files with 8 additions and 3 deletions

View File

@ -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

View File

@ -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;
}
}