Move some test-only code to test files
This also relaxes the bounds on some structs and moves them to the impl block instead.
This commit is contained in:
parent
5c6d3bf389
commit
620ecc01a2
8 changed files with 85 additions and 78 deletions
|
@ -297,22 +297,6 @@ impl<T> TypedArena<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Clears the arena. Deallocates all but the longest chunk which may be reused.
|
||||
pub fn clear(&mut self) {
|
||||
unsafe {
|
||||
// Clear the last chunk, which is partially filled.
|
||||
let mut chunks_borrow = self.chunks.borrow_mut();
|
||||
if let Some(mut last_chunk) = chunks_borrow.last_mut() {
|
||||
self.clear_last_chunk(&mut last_chunk);
|
||||
let len = chunks_borrow.len();
|
||||
// If `T` is ZST, code below has no effect.
|
||||
for mut chunk in chunks_borrow.drain(..len - 1) {
|
||||
chunk.destroy(chunk.entries);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Drops the contents of the last chunk. The last chunk is partially empty, unlike all other
|
||||
// chunks.
|
||||
fn clear_last_chunk(&self, last_chunk: &mut TypedArenaChunk<T>) {
|
||||
|
|
|
@ -11,6 +11,24 @@ struct Point {
|
|||
z: i32,
|
||||
}
|
||||
|
||||
impl<T> TypedArena<T> {
|
||||
/// Clears the arena. Deallocates all but the longest chunk which may be reused.
|
||||
fn clear(&mut self) {
|
||||
unsafe {
|
||||
// Clear the last chunk, which is partially filled.
|
||||
let mut chunks_borrow = self.chunks.borrow_mut();
|
||||
if let Some(mut last_chunk) = chunks_borrow.last_mut() {
|
||||
self.clear_last_chunk(&mut last_chunk);
|
||||
let len = chunks_borrow.len();
|
||||
// If `T` is ZST, code below has no effect.
|
||||
for mut chunk in chunks_borrow.drain(..len - 1) {
|
||||
chunk.destroy(chunk.entries);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
pub fn test_unused() {
|
||||
let arena: TypedArena<Point> = TypedArena::default();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue