This should already have the desired effect.
Unified · Split
| @@ -206,11 +206,16 @@ mod decode { · 205 unmodified lines | |||
| 206 | 206 | ||
| 207 | // Calculate an estimate of the amount of entries to reduce | 207 | // Calculate an estimate of the amount of entries to reduce |
| 208 | // the amount of allocations necessary. | 208 | // the amount of allocations necessary. |
| 209 | // Note that this assumes that we want speed over fitting Vecs, this is a trade-off. | ||
| 209 | // TODO(SHA256): know actual/desired length for reduced overallocation | 210 | // TODO(SHA256): know actual/desired length for reduced overallocation |
| 210 | const HASH_LEN_FIXME: usize = 20; | 211 | const HASH_LEN_FIXME: usize = 20; |
| 211 | let lower_bound_single_entry = 2 + HASH_LEN_FIXME; // 2 = space + trailing zero | 212 | const AVERAGE_FILENAME_LEN: usize = 24; |
| 212 | let upper_bound_entries = i.len() / lower_bound_single_entry; | 213 | const AVERAGE_MODE_LEN: usize = 6; |
| 213 | let mut out = Vec::with_capacity(upper_bound_entries); | 214 | const ENTRY_DELIMITER_LEN: usize = 2; // space + trailing zero |
| 215 | const AVERAGE_TREE_ENTRIES: usize = 16 * 2; // prevent overallocation beyond what's meaningful or what could be dangerous | ||
| 216 | let average_entry_len = ENTRY_DELIMITER_LEN + HASH_LEN_FIXME + AVERAGE_MODE_LEN + AVERAGE_FILENAME_LEN; | ||
| 217 | let upper_bound = i.len() / average_entry_len; | ||
| 218 | let mut out = Vec::with_capacity(upper_bound.min(AVERAGE_TREE_ENTRIES)); | ||
| 214 | 219 | ||
| 215 | while !i.is_empty() { | 220 | while !i.is_empty() { |
| 216 | let Some((rest, entry)) = fast_entry(i) else { | 221 | let Some((rest, entry)) = fast_entry(i) else { |