Skip to content

Commit

Permalink
GH-41: BaseVariableWidthViewVector setZero only if necessary (#557)
Browse files Browse the repository at this point in the history
Closes #41.
  • Loading branch information
ViggoC authored Jan 27, 2025
1 parent b4d6cc0 commit d4f8074
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1367,11 +1367,13 @@ protected ArrowBuf allocateOrGetLastDataBuffer(int length) {
protected final void setBytes(int index, byte[] value, int start, int length) {
int writePosition = index * ELEMENT_SIZE;

// to clear the memory segment of view being written to
// this is helpful in case of overwriting the value
viewBuffer.setZero(writePosition, ELEMENT_SIZE);

if (length <= INLINE_SIZE) {
// Check if the memory segment has been written, and clear it if it has been set.
// It is recommended to batch initialize the viewBuffer before setBytes.
if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) {
viewBuffer.setZero(writePosition, ELEMENT_SIZE);
}

// allocate inline buffer
// set length
viewBuffer.setInt(writePosition, length);
Expand Down Expand Up @@ -1411,11 +1413,13 @@ protected final void setBytes(int index, byte[] value, int start, int length) {
protected final void setBytes(int index, ArrowBuf valueBuf, int start, int length) {
int writePosition = index * ELEMENT_SIZE;

// to clear the memory segment of view being written to
// this is helpful in case of overwriting the value
viewBuffer.setZero(writePosition, ELEMENT_SIZE);

if (length <= INLINE_SIZE) {
// Check if the memory segment has been written, and clear it if it has been set.
// It is recommended to batch initialize the viewBuffer before setBytes.
if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) {
viewBuffer.setZero(writePosition, ELEMENT_SIZE);
}

// allocate inline buffer
// set length
viewBuffer.setInt(writePosition, length);
Expand Down

0 comments on commit d4f8074

Please sign in to comment.