JasonLi-cn commented on code in PR #9732:
URL: https://github.com/apache/arrow-datafusion/pull/9732#discussion_r1550883910


##########
datafusion/physical-expr/src/string_expressions.rs:
##########
@@ -38,75 +40,147 @@ use datafusion_common::{
 };
 use datafusion_expr::ColumnarValue;
 
+enum ColumnarValueRef<'a> {
+    Scalar(&'a [u8]),
+    NullableArray(&'a StringArray),
+    NonNullableArray(&'a StringArray),
+}
+
+impl<'a> ColumnarValueRef<'a> {
+    #[inline]
+    fn is_valid(&self, i: usize) -> bool {
+        match &self {
+            Self::Scalar(_) | Self::NonNullableArray(_) => true,
+            Self::NullableArray(array) => array.is_valid(i),
+        }
+    }
+
+    #[inline]
+    fn nulls(&self) -> Option<NullBuffer> {
+        match &self {
+            Self::Scalar(_) | Self::NonNullableArray(_) => None,
+            Self::NullableArray(array) => array.nulls().cloned(),
+        }
+    }
+}
+
+struct StringArrayBuilder {
+    offsets_buffer: MutableBuffer,
+    value_buffer: MutableBuffer,
+}
+
+impl StringArrayBuilder {
+    fn with_capacity(item_capacity: usize, data_capacity: usize) -> Self {
+        let mut offsets_buffer = MutableBuffer::with_capacity(
+            (item_capacity + 1) * std::mem::size_of::<i32>(),
+        );
+        unsafe { offsets_buffer.push_unchecked(0_i32) };

Review Comment:
   Since it is safe here and there is a theoretical performance improvement, I 
have opted to use `push_unchecked` in this case.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to