Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20871#discussion_r181095730
  
    --- Diff: 
sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/UTF8StringBuilder.java
 ---
    @@ -29,50 +31,41 @@
     
       private static final int ARRAY_MAX = 
ByteArrayMethods.MAX_ROUNDED_ARRAY_LENGTH;
     
    -  private byte[] buffer;
    -  private int cursor = Platform.BYTE_ARRAY_OFFSET;
    +  private ByteArrayMemoryBlock buffer;
    +  private int length = 0;
     
       public UTF8StringBuilder() {
         // Since initial buffer size is 16 in `StringBuilder`, we set the same 
size here
    -    this.buffer = new byte[16];
    +    this.buffer = new ByteArrayMemoryBlock(16);
       }
     
       // Grows the buffer by at least `neededSize`
       private void grow(int neededSize) {
    -    if (neededSize > ARRAY_MAX - totalSize()) {
    +    if (neededSize > ARRAY_MAX - length) {
           throw new UnsupportedOperationException(
             "Cannot grow internal buffer by size " + neededSize + " because 
the size after growing " +
               "exceeds size limitation " + ARRAY_MAX);
         }
    -    final int length = totalSize() + neededSize;
    -    if (buffer.length < 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 int requestedSize = length + neededSize;
    +    if (buffer.size() < requestedSize) {
    --- End diff --
    
    should  `buffer.size()` equal to `length`?


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to