HADOOP-17901. Performance degradation in Text.append() after HADOOP-1… (#3411)
This commit is contained in:
parent
971f1b8b0a
commit
827e19271a
|
@ -268,8 +268,7 @@ public class Text extends BinaryComparable
|
||||||
*/
|
*/
|
||||||
public void append(byte[] utf8, int start, int len) {
|
public void append(byte[] utf8, int start, int len) {
|
||||||
byte[] original = bytes;
|
byte[] original = bytes;
|
||||||
int capacity = Math.max(length + len, length + (length >> 1));
|
if (ensureCapacity(length + len)) {
|
||||||
if (ensureCapacity(capacity)) {
|
|
||||||
System.arraycopy(original, 0, bytes, 0, length);
|
System.arraycopy(original, 0, bytes, 0, length);
|
||||||
}
|
}
|
||||||
System.arraycopy(utf8, start, bytes, length, len);
|
System.arraycopy(utf8, start, bytes, length, len);
|
||||||
|
@ -302,7 +301,10 @@ public class Text extends BinaryComparable
|
||||||
*/
|
*/
|
||||||
private boolean ensureCapacity(final int capacity) {
|
private boolean ensureCapacity(final int capacity) {
|
||||||
if (bytes.length < capacity) {
|
if (bytes.length < capacity) {
|
||||||
bytes = new byte[capacity];
|
// Try to expand the backing array by the factor of 1.5x
|
||||||
|
// (by taking the current size + diving it by half)
|
||||||
|
int targetSize = Math.max(capacity, bytes.length + (bytes.length >> 1));
|
||||||
|
bytes = new byte[targetSize];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue