| 88 | } |
| 89 | |
| 90 | pub fn reserve(&mut self, additional: usize) { |
| 91 | if additional > sub_ptr(self.capacity, self.end) { |
| 92 | #[cold] |
| 93 | #[inline(never)] |
| 94 | fn reserve_slow<T>(me: &mut FastVec<T>, additional: usize) { |
| 95 | // Safety: `Vec::reserve` panics on OOM without freeing Vec, so Vec is unmodified. |
| 96 | unsafe { |
| 97 | me.mut_vec(|v| { |
| 98 | // Optimizes out a redundant check in `Vec::reserve`. |
| 99 | // Safety: we've already ensured this condition before calling reserve_slow. |
| 100 | if additional <= v.capacity().wrapping_sub(v.len()) { |
| 101 | std::hint::unreachable_unchecked(); |
| 102 | } |
| 103 | v.reserve(additional); |
| 104 | }); |
| 105 | } |
| 106 | } |
| 107 | reserve_slow(self, additional); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | /// Accesses the [`FastVec`] mutably as a [`Vec`]. |
| 112 | /// # Safety |