Jefffrey commented on code in PR #10923:
URL: https://github.com/apache/arrow-rs/pull/10923#discussion_r3892070734


##########
arrow-avro/src/reader/record.rs:
##########
@@ -733,9 +718,9 @@ impl Decoder {
             | Self::Array(_, offsets, _)
             | Self::Map(_, _, offsets, _, _) => {
                 offsets.reserve(count);
-                for _ in 0..count {
-                    offsets.push_length(0);
-                }
+                let offset = *offsets.last().expect("offsets cannot be empty");
+                let new_len = 
offsets.len().checked_add(count).expect("overflow");
+                offsets.resize(new_len, offset);

Review Comment:
   we do both reserve & resize here; probably can get away with resize only?
   
   also would be good to raise error on the second expect (calculating 
`new_len`)



##########
arrow-avro/src/reader/record.rs:
##########
@@ -2397,8 +2382,32 @@ fn flush_values<T>(values: &mut Vec<T>) -> Vec<T> {
 }
 
 #[inline]
-fn flush_offsets(offsets: &mut OffsetBufferBuilder<i32>) -> OffsetBuffer<i32> {
-    std::mem::replace(offsets, 
OffsetBufferBuilder::new(DEFAULT_CAPACITY)).finish()
+fn new_offsets() -> Vec<i32> {
+    let mut offsets = Vec::with_capacity(DEFAULT_CAPACITY + 1);
+    offsets.push(0);
+    offsets
+}
+
+#[inline]
+fn push_offset(offsets: &mut Vec<i32>, offset: usize) {
+    let offset = i32::try_from(offset).expect("overflow");
+    debug_assert!(offset >= *offsets.last().expect("offsets cannot be empty"));
+    offsets.push(offset);
+}
+
+#[inline]
+fn push_length(offsets: &mut Vec<i32>, length: usize) {
+    let length = i32::try_from(length).expect("overflow");
+    let last = *offsets.last().expect("offsets cannot be empty");
+    offsets.push(last.checked_add(length).expect("overflow"));
+}

Review Comment:
   similarly here for overflow checks



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