krtab commented on code in PR #12304:
URL: https://github.com/apache/arrow-rs/pull/12304#discussion_r4664461254


##########
parquet_derive/src/lib.rs:
##########
@@ -254,11 +254,16 @@ pub fn parquet_record_reader(input: 
proc_macro::TokenStream) -> proc_macro::Toke
         let mut row_group_reader = row_group_reader;
 
         // key: parquet file column name, value: column index
-        let mut name_to_index = std::collections::HashMap::new();
-        for (idx, col) in 
row_group_reader.metadata().schema_descr().columns().iter().enumerate() {
-            name_to_index.insert(col.name().to_string(), idx);
-        }
-
+        let name_to_index : std::collections::HashMap<_,_> = row_group_reader
+            .metadata()
+            .schema_descr()
+            .columns()
+            .iter()
+            .map(|col| col.name().to_string())
+            .enumerate()
+            .map(|(col,idx)| (idx,col))
+            .collect();
+        self.reserve(num_records);

Review Comment:
   I feel like `reserv`ing before pushing in a loop is a good practice, 
especially in a macro when generating code.
   
   I haven't observed the extra allocations from before to have practical 
impact but I feel like it is always best to reduce unneeded allocations if 
possible.



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