File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -28,18 +28,13 @@ impl<T> RawVec<T> {
28
28
}
29
29
30
30
fn grow(&mut self) {
31
- let (new_cap, new_layout) = if self.cap == 0 {
32
- (1, Layout::array::<T>(1).unwrap())
33
- } else {
34
- // This can't overflow because we ensure self.cap <= isize::MAX.
35
- let new_cap = 2 * self.cap;
36
-
37
- // Layout::array checks that the number of bytes is <= usize::MAX,
38
- // but this is redundant since old_layout.size() <= isize::MAX,
39
- // so the `unwrap` should never fail.
40
- let new_layout = Layout::array::<T>(new_cap).unwrap();
41
- (new_cap, new_layout)
42
- };
31
+ // This can't overflow because we ensure self.cap <= isize::MAX.
32
+ let new_cap = if self.cap == 0 { 1 } else { 2 * self.cap };
33
+
34
+ // Layout::array checks that the number of bytes is <= usize::MAX,
35
+ // but this is redundant since old_layout.size() <= isize::MAX,
36
+ // so the `unwrap` should never fail.
37
+ let new_layout = Layout::array::<T>(new_cap).unwrap();
43
38
44
39
// Ensure that the new allocation doesn't exceed `isize::MAX` bytes.
45
40
assert!(new_layout.size() <= isize::MAX as usize, "Allocation too large");
You can’t perform that action at this time.
0 commit comments