This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-java.git


The following commit(s) were added to refs/heads/main by this push:
     new d4f8074d GH-41: BaseVariableWidthViewVector setZero only if necessary 
(#557)
d4f8074d is described below

commit d4f8074dd82ea3f59618fd43e58a1ba04186718c
Author: ViggoC <[email protected]>
AuthorDate: Mon Jan 27 12:31:43 2025 +0800

    GH-41: BaseVariableWidthViewVector setZero only if necessary (#557)
    
    Closes #41.
---
 .../arrow/vector/BaseVariableWidthViewVector.java    | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git 
a/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java 
b/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java
index 15d21827..e0e16762 100644
--- 
a/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java
+++ 
b/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java
@@ -1367,11 +1367,13 @@ public abstract class BaseVariableWidthViewVector 
extends BaseValueVector
   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);
@@ -1411,11 +1413,13 @@ public abstract class BaseVariableWidthViewVector 
extends BaseValueVector
   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);

Reply via email to