You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by viirya <gi...@git.apache.org> on 2018/04/06 06:55:39 UTC
[GitHub] spark pull request #20871: [SPARK-23762][SQL] UTF8StringBuffer uses MemoryBl...
Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/20871#discussion_r179673734
--- Diff: sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/UTF8StringBuilder.java ---
@@ -45,34 +47,29 @@ private void grow(int neededSize) {
"exceeds size limitation " + ARRAY_MAX);
}
final int length = totalSize() + neededSize;
- if (buffer.length < length) {
+ if (buffer.size() < length) {
int newLength = length < ARRAY_MAX / 2 ? length * 2 : ARRAY_MAX;
- final byte[] tmp = new byte[newLength];
- Platform.copyMemory(
- buffer,
- Platform.BYTE_ARRAY_OFFSET,
- tmp,
- Platform.BYTE_ARRAY_OFFSET,
- totalSize());
+ final ByteArrayMemoryBlock tmp = new ByteArrayMemoryBlock(newLength);
+ MemoryBlock.copyMemory(buffer, tmp, totalSize());
buffer = tmp;
}
}
private int totalSize() {
- return cursor - Platform.BYTE_ARRAY_OFFSET;
+ return length;
--- End diff --
Since `totalSize` is privately used only, and now it is simply `length`, I think we can remove it and just use `length`.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org