Skip to content
Merged
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 @@ -159,7 +159,7 @@ public void read(BinaryBuffer values, int offset, int length)
currentInputOffset += positionLength + Integer.BYTES;
}

createOutputBuffer(values, offset, length, inputSlice, outputBufferSize);
values.addChunk(createOutputBuffer(values.getOffsets(), offset, length, inputSlice, outputBufferSize));
input.skip(currentInputOffset);
}

Expand All @@ -168,6 +168,36 @@ public void skip(int n)
{
skipPlainValues(input, n);
}

/**
* Create one big slice of data and add it to the output buffer since buffer size is known.
* Specialized for the case of strings with no truncation
*/
private static Slice createOutputBuffer(int[] offsets, int offset, int length, Slice inputSlice, int outputBufferSize)
Copy link
Member

Choose a reason for hiding this comment

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

so offsets have double meaning? As in it's length as out it's offset? Would be good to have that commented

{
byte[] outputBuffer = new byte[outputBufferSize];
int currentInputOffset = 0;
int currentOutputOffset = 0;

byte[] inputArray;
int inputArrayOffset;
if (length != 0) {
inputArray = inputSlice.byteArray();
inputArrayOffset = inputSlice.byteArrayOffset();
}
else {
inputArray = new byte[0];
inputArrayOffset = 0;
}
for (int i = 0; i < length; i++) {
int positionLength = offsets[offset + i + 1];
arraycopy(inputArray, inputArrayOffset + currentInputOffset + Integer.BYTES, outputBuffer, currentOutputOffset, positionLength);
offsets[offset + i + 1] = offsets[offset + i] + positionLength;
currentInputOffset += positionLength + Integer.BYTES;
Copy link
Member

Choose a reason for hiding this comment

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

Why add BYTES here and in arraycopy? Just add BYTES * 2?

currentOutputOffset += positionLength;
}
return Slices.wrappedBuffer(outputBuffer);
}
}

private static void skipPlainValues(SimpleSliceInputStream input, int n)
Expand Down