Skip to content

Commit d4f8074

Browse files
authored
GH-41: BaseVariableWidthViewVector setZero only if necessary (#557)
Closes #41.
1 parent b4d6cc0 commit d4f8074

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,11 +1367,13 @@ protected ArrowBuf allocateOrGetLastDataBuffer(int length) {
13671367
protected final void setBytes(int index, byte[] value, int start, int length) {
13681368
int writePosition = index * ELEMENT_SIZE;
13691369

1370-
// to clear the memory segment of view being written to
1371-
// this is helpful in case of overwriting the value
1372-
viewBuffer.setZero(writePosition, ELEMENT_SIZE);
1373-
13741370
if (length <= INLINE_SIZE) {
1371+
// Check if the memory segment has been written, and clear it if it has been set.
1372+
// It is recommended to batch initialize the viewBuffer before setBytes.
1373+
if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) {
1374+
viewBuffer.setZero(writePosition, ELEMENT_SIZE);
1375+
}
1376+
13751377
// allocate inline buffer
13761378
// set length
13771379
viewBuffer.setInt(writePosition, length);
@@ -1411,11 +1413,13 @@ protected final void setBytes(int index, byte[] value, int start, int length) {
14111413
protected final void setBytes(int index, ArrowBuf valueBuf, int start, int length) {
14121414
int writePosition = index * ELEMENT_SIZE;
14131415

1414-
// to clear the memory segment of view being written to
1415-
// this is helpful in case of overwriting the value
1416-
viewBuffer.setZero(writePosition, ELEMENT_SIZE);
1417-
14181416
if (length <= INLINE_SIZE) {
1417+
// Check if the memory segment has been written, and clear it if it has been set.
1418+
// It is recommended to batch initialize the viewBuffer before setBytes.
1419+
if (viewBuffer.getLong(writePosition) != 0 || viewBuffer.getLong(writePosition + 8) != 0) {
1420+
viewBuffer.setZero(writePosition, ELEMENT_SIZE);
1421+
}
1422+
14191423
// allocate inline buffer
14201424
// set length
14211425
viewBuffer.setInt(writePosition, length);

0 commit comments

Comments
 (0)