Skip to content
Closed
Changes from 1 commit
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 @@ -993,7 +993,7 @@ public static UTF8String concatWs(UTF8String separator, UTF8String... inputs) {
return null;
}

int numInputBytes = 0; // total number of bytes from the inputs
long numInputBytes = 0L; // total number of bytes from the inputs
int numInputs = 0; // number of non-null inputs
for (int i = 0; i < inputs.length; i++) {
if (inputs[i] != null) {
Expand All @@ -1009,7 +1009,8 @@ public static UTF8String concatWs(UTF8String separator, UTF8String... inputs) {

// Allocate a new byte array, and copy the inputs one by one into it.
// The size of the new array is the size of all inputs, plus the separators.
final byte[] result = new byte[numInputBytes + (numInputs - 1) * separator.numBytes];
int intNumInputBytes = Ints.checkedCast(numInputBytes + (numInputs - 1) * separator.numBytes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you use guava here instead of just checking numInputBytes > Int.MaxValue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code just follow the concat that do the same check.

final byte[] result = new byte[Ints.checkedCast(totalLength)];

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use Math.toIntExact, and replace Ints.checkedCast by toIntExact, please. I don't see any benefits of the Guava function over the standard function, do you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced it.

final byte[] result = new byte[intNumInputBytes];
int offset = 0;

for (int i = 0, j = 0; i < inputs.length; i++) {
Expand Down