Skip to content

Commit 1d75cf3

Browse files
committed
address review comment
1 parent ba81497 commit 1d75cf3

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/UTF8StringBuilder.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,20 @@ public UTF8StringBuilder() {
4141

4242
// Grows the buffer by at least `neededSize`
4343
private void grow(int neededSize) {
44-
if (neededSize > ARRAY_MAX - totalSize()) {
44+
if (neededSize > ARRAY_MAX - length) {
4545
throw new UnsupportedOperationException(
4646
"Cannot grow internal buffer by size " + neededSize + " because the size after growing " +
4747
"exceeds size limitation " + ARRAY_MAX);
4848
}
49-
final int length = totalSize() + neededSize;
50-
if (buffer.size() < length) {
51-
int newLength = length < ARRAY_MAX / 2 ? length * 2 : ARRAY_MAX;
49+
final int requestedSize = length + neededSize;
50+
if (buffer.size() < requestedSize) {
51+
int newLength = requestedSize < ARRAY_MAX / 2 ? requestedSize * 2 : ARRAY_MAX;
5252
final ByteArrayMemoryBlock tmp = new ByteArrayMemoryBlock(newLength);
53-
MemoryBlock.copyMemory(buffer, tmp, totalSize());
53+
MemoryBlock.copyMemory(buffer, tmp, length);
5454
buffer = tmp;
5555
}
5656
}
5757

58-
private int totalSize() {
59-
return length;
60-
}
61-
6258
public void append(UTF8String value) {
6359
grow(value.numBytes());
6460
value.writeToMemory(buffer.getByteArray(), length + Platform.BYTE_ARRAY_OFFSET);
@@ -70,6 +66,6 @@ public void append(String value) {
7066
}
7167

7268
public UTF8String build() {
73-
return UTF8String.fromBytes(buffer.getByteArray(), 0, totalSize());
69+
return UTF8String.fromBytes(buffer.getByteArray(), 0, length);
7470
}
7571
}

0 commit comments

Comments
 (0)