chloro-pn commented on code in PR #6178:
URL: https://github.com/apache/arrow-rs/pull/6178#discussion_r1709345832


##########
arrow-buffer/src/buffer/mutable.rs:
##########
@@ -668,6 +668,56 @@ impl MutableBuffer {
     }
 }
 
+impl<'a> MutableBuffer {
+    /// Creates a [`MutableBuffer`] from an `&[u8]` [`Iterator`] with a 
trusted (upper) length.
+    /// Prefer this to `collect` whenever possible, as it is faster.
+    /// # Panic
+    /// This method will panic if `&u8.len()` != `item_size`.
+    /// # Example
+    /// ```
+    /// # use arrow_buffer::MutableBuffer;
+    /// # use arrow_buffer::ToByteSlice;
+    /// let iter = vec![[1_u8, 2].to_byte_slice(), [3_u8, 
4].to_byte_slice()].into_iter();
+    /// let buf = unsafe {
+    ///     MutableBuffer::from_trusted_len_iter_slice_u8(iter, 2)
+    /// };
+    /// assert_eq!(4, buf.len());
+    /// ```
+    /// # Safety
+    /// This method assumes that the iterator's size is correct and is 
undefined behavior
+    /// to use it on an iterator that reports an incorrect length.
+    // This implementation is required for two reasons:
+    // 1. there is no trait `TrustedLen` in stable rust and therefore
+    //    we can't specialize `extend` for `TrustedLen` like `Vec` does.
+    // 2. `from_trusted_len_iter_slice_u8` is faster.
+    #[inline]
+    pub unsafe fn from_trusted_len_iter_slice_u8<I: Iterator<Item = &'a [u8]>>(

Review Comment:
   the "faster" here means `"/// Prefer this to collect whenever possible, as 
it is faster."`.
   which appears in the first half of this function's comment.
   * from_trusted_len_iter
   * from_trusted_len_iter_bool
   * from_trusted_len_iter_slice_u8
   
   The logic implemented by these functions is similar, and the comment are 
also similar.



-- 
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