@@ -221,16 +221,16 @@ pub fn parse_daf_comment_area(
221
221
input : & [ u8 ] ,
222
222
comment_areas_count : u32 ,
223
223
) -> nom:: IResult < & [ u8 ] , String > {
224
- // This function is definetely not optimal as there are several allocations at
225
- // different points but this is not a hot data path.
226
- let mut comment_area = String :: new ( ) ;
224
+ let record_size = 1000 ;
225
+
226
+ let mut comment_area = String :: with_capacity ( ( comment_areas_count * record_size ) as usize ) ;
227
227
228
228
let mut input_cursor = input;
229
229
for _ in 0 ..comment_areas_count {
230
230
let comment_areas;
231
231
( input_cursor, comment_areas) = nb:: take ( RECORD_SIZE ) ( input_cursor) ?;
232
232
233
- let ( _, comment_record_content) = nb:: take ( 1000u32 ) ( comment_areas) ?;
233
+ let ( _, comment_record_content) = nb:: take ( record_size ) ( comment_areas) ?;
234
234
235
235
let comment_record_content = match nb:: take_until ( "\x04 " ) ( comment_record_content) {
236
236
Ok ( ( _, content_to_end_of_transmission_char) ) => content_to_end_of_transmission_char,
@@ -267,8 +267,6 @@ pub fn parse_daf_summary_and_name_record_pair(
267
267
268
268
let nc = 8 * ( nd + ( ni + 1 ) / 2 ) ;
269
269
270
- let mut summaries = Vec :: new ( ) ;
271
-
272
270
// 1. The record number of the next summary record in the file. (Zero if this is
273
271
// the final summary record.)
274
272
let ( summary_record_input, next) = nn:: f64 ( endianness) ( summary_record_input) ?;
@@ -282,6 +280,8 @@ pub fn parse_daf_summary_and_name_record_pair(
282
280
let ( mut summary_record_input, nsum) = nn:: f64 ( endianness) ( summary_record_input) ?;
283
281
let nsum = nsum as u32 ;
284
282
283
+ let mut summaries = Vec :: with_capacity ( nsum as usize ) ;
284
+
285
285
for _ in 0 ..nsum {
286
286
let double_precision_components;
287
287
( summary_record_input, double_precision_components) =
0 commit comments