alamb commented on code in PR #7922:
URL: https://github.com/apache/arrow-rs/pull/7922#discussion_r2207866251


##########
parquet-variant/src/builder.rs:
##########
@@ -402,6 +402,11 @@ impl<S: AsRef<str>> FromIterator<S> for MetadataBuilder {
 
 impl<S: AsRef<str>> Extend<S> for MetadataBuilder {
     fn extend<T: IntoIterator<Item = S>>(&mut self, iter: T) {
+        let iter = iter.into_iter();
+        let (min, max) = iter.size_hint();
+
+        self.field_names.reserve(max.unwrap_or(min));
+
         for field_name in iter {
             self.upsert_field_name(field_name.as_ref());

Review Comment:
   I agree in theory it is not a great idea
   
   However in practice I think it is common to reserve capacity (allocate) 
based on the size hint and it is done several other places in this crate
   
   
https://github.com/apache/arrow-rs/blob/474f1924fff30d3150f7c737205bb9f903686d53/parquet/src/arrow/arrow_reader/selection.rs#L129-L128
   
   
https://github.com/apache/arrow-rs/blob/be338f9bdaab719dd569130ea882e10a58ef9d17/arrow-array/src/array/primitive_array.rs#L1408-L1407
   
   
https://github.com/apache/arrow-rs/blob/a2cc42639b4ad5579d052e6f2317a413e2407e0f/arrow-array/src/array/boolean_array.rs#L435-L434
   
   I also think it is done in the standard library for `Vec` , for example in 
https://doc.rust-lang.org/src/alloc/vec/mod.rs.html#3550
   
   <img width="1138" height="732" alt="Screenshot 2025-07-15 at 11 36 06 AM" 
src="https://github.com/user-attachments/assets/83e7311f-1de2-4b21-a983-94a348574992";
 />
   
   
   Thus I think it is acceptable to do here too
   
   



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to