|
|
@ -28,18 +28,13 @@ impl<T> RawVec<T> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn grow(&mut self) {
|
|
|
|
fn grow(&mut self) {
|
|
|
|
let (new_cap, new_layout) = if self.cap == 0 {
|
|
|
|
// This can't overflow because we ensure self.cap <= isize::MAX.
|
|
|
|
(1, Layout::array::<T>(1).unwrap())
|
|
|
|
let new_cap = if self.cap == 0 { 1 } else { 2 * self.cap };
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// This can't overflow because we ensure self.cap <= isize::MAX.
|
|
|
|
// Layout::array checks that the number of bytes is <= usize::MAX,
|
|
|
|
let new_cap = 2 * self.cap;
|
|
|
|
// but this is redundant since old_layout.size() <= isize::MAX,
|
|
|
|
|
|
|
|
// so the `unwrap` should never fail.
|
|
|
|
// Layout::array checks that the number of bytes is <= usize::MAX,
|
|
|
|
let new_layout = Layout::array::<T>(new_cap).unwrap();
|
|
|
|
// but this is redundant since old_layout.size() <= isize::MAX,
|
|
|
|
|
|
|
|
// so the `unwrap` should never fail.
|
|
|
|
|
|
|
|
let new_layout = Layout::array::<T>(new_cap).unwrap();
|
|
|
|
|
|
|
|
(new_cap, new_layout)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure that the new allocation doesn't exceed `isize::MAX` bytes.
|
|
|
|
// Ensure that the new allocation doesn't exceed `isize::MAX` bytes.
|
|
|
|
assert!(new_layout.size() <= isize::MAX as usize, "Allocation too large");
|
|
|
|
assert!(new_layout.size() <= isize::MAX as usize, "Allocation too large");
|
|
|
|