Fix formatting
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
use std::{ffi::c_void, sync::{LazyLock, Mutex}};
|
use std::{
|
||||||
|
ffi::c_void,
|
||||||
|
sync::{LazyLock, Mutex},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Reallocator {
|
struct Reallocator {
|
||||||
@@ -55,7 +58,8 @@ impl Reallocator {
|
|||||||
// actually reallocate and copy the data over
|
// actually reallocate and copy the data over
|
||||||
let mut new_data = Allocation::new(new_size);
|
let mut new_data = Allocation::new(new_size);
|
||||||
let bytes_to_copy = old_data.size.min(new_size);
|
let bytes_to_copy = old_data.size.min(new_size);
|
||||||
new_data.as_mut_slice()[..bytes_to_copy].copy_from_slice(&old_data.as_slice()[..bytes_to_copy]);
|
new_data.as_mut_slice()[..bytes_to_copy]
|
||||||
|
.copy_from_slice(&old_data.as_slice()[..bytes_to_copy]);
|
||||||
self.store_allocation(new_data)
|
self.store_allocation(new_data)
|
||||||
}
|
}
|
||||||
} else if new_size > 0 {
|
} else if new_size > 0 {
|
||||||
@@ -71,7 +75,11 @@ impl Reallocator {
|
|||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let index = self.allocations.iter().enumerate().find_map(|(i, alloc)| std::ptr::addr_eq(alloc.ptr, ptr).then_some(i))?;
|
let index = self
|
||||||
|
.allocations
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.find_map(|(i, alloc)| std::ptr::addr_eq(alloc.ptr, ptr).then_some(i))?;
|
||||||
let allocation = self.allocations.remove(index);
|
let allocation = self.allocations.remove(index);
|
||||||
Some(allocation)
|
Some(allocation)
|
||||||
}
|
}
|
||||||
@@ -83,7 +91,8 @@ impl Reallocator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static VBU_ALLOC: LazyLock<Mutex<Reallocator>> = LazyLock::new(|| Mutex::new(Reallocator::default()));
|
static VBU_ALLOC: LazyLock<Mutex<Reallocator>> =
|
||||||
|
LazyLock::new(|| Mutex::new(Reallocator::default()));
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
#[allow(nonstandard_style)]
|
#[allow(nonstandard_style)]
|
||||||
|
|||||||
Reference in New Issue
Block a user