Constant nom::multi::MAX_INITIAL_CAPACITY_BYTES

source ·
const MAX_INITIAL_CAPACITY_BYTES: usize = 65536;
Expand description

Don’t pre-allocate more than 64KiB when calling Vec::with_capacity.

Pre-allocating memory is a nice optimization but count fields can’t always be trusted. We should clamp initial capacities to some reasonable amount. This reduces the risk of a bogus count value triggering a panic due to an OOM error.

This does not affect correctness. Nom will always read the full number of elements regardless of the capacity cap.