mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #155161 - saethlin:push_mut_saves, r=Kivooeo
Use Vec::push_mut when adding a chunk to arenas This fixes https://github.com/rust-lang/rust/issues/155148, which may or may not be worth fixing on its own merits, but I think `Vec::push_mut` also makes the code nicer.
This commit is contained in:
@@ -287,10 +287,9 @@ fn grow(&self, additional: usize) {
|
||||
// Also ensure that this chunk can fit `additional`.
|
||||
new_cap = cmp::max(additional, new_cap);
|
||||
|
||||
let mut chunk = ArenaChunk::<T>::new(new_cap);
|
||||
let chunk = chunks.push_mut(ArenaChunk::<T>::new(new_cap));
|
||||
self.ptr.set(chunk.start());
|
||||
self.end.set(chunk.end());
|
||||
chunks.push(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -419,7 +418,7 @@ fn grow(&self, layout: Layout) {
|
||||
// Also ensure that this chunk can fit `additional`.
|
||||
new_cap = cmp::max(additional, new_cap);
|
||||
|
||||
let mut chunk = ArenaChunk::new(align_up(new_cap, PAGE));
|
||||
let chunk = chunks.push_mut(ArenaChunk::new(align_up(new_cap, PAGE)));
|
||||
self.start.set(chunk.start());
|
||||
|
||||
// Align the end to DROPLESS_ALIGNMENT.
|
||||
@@ -430,8 +429,6 @@ fn grow(&self, layout: Layout) {
|
||||
debug_assert!(chunk.start().addr() <= end);
|
||||
|
||||
self.end.set(chunk.end().with_addr(end));
|
||||
|
||||
chunks.push(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,11 +58,10 @@ fn grow(&self, additional: usize) {
|
||||
// Also ensure that this chunk can fit `additional`.
|
||||
new_cap = cmp::max(additional, new_cap);
|
||||
|
||||
let mut chunk = Box::new_uninit_slice(new_cap);
|
||||
let chunk = chunks.push_mut(Box::new_uninit_slice(new_cap));
|
||||
let Range { start, end } = chunk.as_mut_ptr_range();
|
||||
self.start.set(start);
|
||||
self.end.set(end);
|
||||
chunks.push(chunk);
|
||||
}
|
||||
|
||||
/// Allocates a byte slice with specified size from the current memory
|
||||
|
||||
Reference in New Issue
Block a user