Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/7533#discussion_r36016677
  
    --- Diff: 
unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java ---
    @@ -144,24 +144,28 @@ public int numChars() {
        */
       public UTF8String substring(final int start, final int until) {
         if (until <= start || start >= numBytes) {
    -      return fromBytes(new byte[0]);
    +      return UTF8String.EMPTY_UTF8;
         }
    +    int j = firstByteIndex(0, 0, start);
    +    int i = firstByteIndex(j, start, until);
    +    byte[] bytes = new byte[i - j];
    +    copyMemory(base, offset + j, bytes, BYTE_ARRAY_OFFSET, i - j);
    +    return fromBytes(bytes);
    +  }
     
    -    int i = 0;
    -    int c = 0;
    -    while (i < numBytes && c < start) {
    -      i += numBytesForFirstByte(getByte(i));
    -      c += 1;
    +  /**
    +   * Returns a substring of this from start to end.
    +   * @param start the position of first code point
    +   */
    +  public UTF8String substring(final int start) {
    +    if (start >= numBytes) {
    +      return fromBytes(new byte[0]);
         }
     
    -    int j = i;
    -    while (i < numBytes && c < until) {
    -      i += numBytesForFirstByte(getByte(i));
    -      c += 1;
    -    }
    +    int i = firstByteIndex(0, 0, start);
    --- End diff --
    
    check if i == numBytes


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to