Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.esotericsoftware.kryo.KryoSerializable;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.google.common.primitives.Ints;

import org.apache.spark.unsafe.Platform;
import org.apache.spark.unsafe.UTF8StringBuilder;
Expand Down Expand Up @@ -764,7 +763,7 @@ public UTF8String repeat(int times) {
return EMPTY_UTF8;
}

byte[] newBytes = new byte[numBytes * times];
byte[] newBytes = new byte[Math.multiplyExact(numBytes, times)];
copyMemory(this.base, this.offset, newBytes, BYTE_ARRAY_OFFSET, numBytes);

int copied = 1;
Expand Down Expand Up @@ -907,7 +906,8 @@ public UTF8String rpad(int len, UTF8String pad) {
// the partial string of the padding
UTF8String remain = pad.substring(0, spaces - padChars * count);

byte[] data = new byte[this.numBytes + pad.numBytes * count + remain.numBytes];
int resultSize = Math.toIntExact((long)numBytes + pad.numBytes * count + remain.numBytes);
byte[] data = new byte[resultSize];
copyMemory(this.base, this.offset, data, BYTE_ARRAY_OFFSET, this.numBytes);
int offset = this.numBytes;
int idx = 0;
Expand Down Expand Up @@ -939,7 +939,8 @@ public UTF8String lpad(int len, UTF8String pad) {
// the partial string of the padding
UTF8String remain = pad.substring(0, spaces - padChars * count);

byte[] data = new byte[this.numBytes + pad.numBytes * count + remain.numBytes];
int resultSize = Math.toIntExact((long)numBytes + pad.numBytes * count + remain.numBytes);
byte[] data = new byte[resultSize];

int offset = 0;
int idx = 0;
Expand Down Expand Up @@ -971,7 +972,7 @@ public static UTF8String concat(UTF8String... inputs) {
}

// Allocate a new byte array, and copy the inputs one by one into it.
final byte[] result = new byte[Ints.checkedCast(totalLength)];
final byte[] result = new byte[Math.toIntExact(totalLength)];
int offset = 0;
for (int i = 0; i < inputs.length; i++) {
int len = inputs[i].numBytes;
Expand Down