@@ -20,7 +20,7 @@ use core::num::NonZeroUsize;
20
20
///
21
21
/// This does not affect correctness. Nom will always read the full number
22
22
/// of elements regardless of the capacity cap.
23
- const MAX_INITIAL_CAPACITY : usize = 65536 ;
23
+ const MAX_INITIAL_CAPACITY_BYTES : usize = 65536 ;
24
24
25
25
/// Repeats the embedded parser until it fails
26
26
/// and returns the results in a `Vec`.
@@ -373,7 +373,8 @@ where
373
373
return Err ( Err :: Failure ( E :: from_error_kind ( input, ErrorKind :: ManyMN ) ) ) ;
374
374
}
375
375
376
- let mut res = crate :: lib:: std:: vec:: Vec :: with_capacity ( min. clamp ( 0 , MAX_INITIAL_CAPACITY ) ) ;
376
+ let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES / std:: mem:: size_of :: < O > ( ) ;
377
+ let mut res = crate :: lib:: std:: vec:: Vec :: with_capacity ( min. clamp ( 0 , max_initial_capacity) ) ;
377
378
for count in 0 ..max {
378
379
let len = input. input_len ( ) ;
379
380
match parse. parse ( input. clone ( ) ) {
@@ -540,7 +541,8 @@ where
540
541
{
541
542
move |i : I | {
542
543
let mut input = i. clone ( ) ;
543
- let mut res = crate :: lib:: std:: vec:: Vec :: with_capacity ( count. clamp ( 0 , MAX_INITIAL_CAPACITY ) ) ;
544
+ let max_initial_capacity = MAX_INITIAL_CAPACITY_BYTES / std:: mem:: size_of :: < O > ( ) ;
545
+ let mut res = crate :: lib:: std:: vec:: Vec :: with_capacity ( count. clamp ( 0 , max_initial_capacity) ) ;
544
546
545
547
for _ in 0 ..count {
546
548
let input_ = input. clone ( ) ;
0 commit comments