Removing some safety because of cost overhead
This commit is contained in:
parent
42349a315e
commit
44288828a2
@ -1,5 +0,0 @@
|
||||
pub unsafe trait Dyn<T: Sized>: Drop + Sized {
|
||||
fn getRef<'s>(&'s self) -> &'s mut T;
|
||||
fn free<'s>(&'s mut self);
|
||||
}
|
||||
|
||||
@ -1,27 +1,23 @@
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
pub unsafe trait GeneralPurposeHeap {
|
||||
type Dyn<T: Sized>: crate::Dyn<T>;
|
||||
|
||||
fn alloc<'s, T: Sized>(&'s mut self, value: T) -> Self::Dyn<T> {
|
||||
return self
|
||||
.tryAlloc(value)
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
fn alloc<'s, T: Sized>(&'s mut self, value: T) -> &'s mut T {
|
||||
return self.tryAlloc(value).unwrap_or_else(|| crate::panicOOM());
|
||||
}
|
||||
|
||||
fn allocUninitialized<'s, T: Sized>(&'s mut self) -> Self::Dyn<MaybeUninit<T>> {
|
||||
fn allocUninitialized<'s, T: Sized>(&'s mut self) -> &'s mut MaybeUninit<T> {
|
||||
return self
|
||||
.tryAllocUninitialized()
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
.unwrap_or_else(|| crate::panicOOM());
|
||||
}
|
||||
|
||||
fn allocZeroed<'s, T: Sized>(&'s mut self) -> Self::Dyn<MaybeUninit<T>> {
|
||||
fn allocZeroed<'s, T: Sized>(&'s mut self) -> &'s mut MaybeUninit<T> {
|
||||
return self
|
||||
.tryAllocZeroed()
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
.unwrap_or_else(|| crate::panicOOM());
|
||||
}
|
||||
|
||||
fn tryAlloc<'s, T: Sized>(&'s mut self, value: T) -> Option<Self::Dyn<T>>;
|
||||
fn tryAllocUninitialized<'s, T: Sized>(&'s mut self) -> Option<Self::Dyn<MaybeUninit<T>>>;
|
||||
fn tryAllocZeroed<'s, T: Sized>(&'s mut self) -> Option<Self::Dyn<MaybeUninit<T>>>;
|
||||
fn tryAlloc<'s, T: Sized>(&'s mut self, value: T) -> Option<&'s mut T>;
|
||||
fn tryAllocUninitialized<'s, T: Sized>(&'s mut self) -> Option<&'s mut MaybeUninit<T>>;
|
||||
fn tryAllocZeroed<'s, T: Sized>(&'s mut self) -> Option<&'s mut MaybeUninit<T>>;
|
||||
}
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
mod r#dyn;
|
||||
#[allow(drop_bounds)]
|
||||
|
||||
mod general;
|
||||
mod pages;
|
||||
mod stack;
|
||||
mod typed;
|
||||
|
||||
pub fn panicOOM() -> ! {
|
||||
panic!("Out of memory");
|
||||
}
|
||||
|
||||
pub use pages::Page;
|
||||
pub use pages::PagesManager;
|
||||
pub use r#dyn::Dyn;
|
||||
pub use stack::StackHeap;
|
||||
pub use typed::TypedHeap;
|
||||
pub use general::GeneralPurposeHeap;
|
||||
@ -1,12 +1,13 @@
|
||||
use std::ptr::NonNull;
|
||||
|
||||
enum ExtensionResult {
|
||||
pub enum ExtensionResult {
|
||||
OK,
|
||||
NO_MEMORY,
|
||||
EXTENSION_BUSY,
|
||||
NOT_SUPPORTED,
|
||||
}
|
||||
|
||||
pub unsafe trait Page {
|
||||
pub unsafe trait Page: Drop + Sized {
|
||||
fn getMemory(&self) -> NonNull<[u8]>;
|
||||
|
||||
fn releasePage(self);
|
||||
@ -17,11 +18,11 @@ pub unsafe trait Page {
|
||||
pub unsafe trait PagesManager {
|
||||
type Page: Page;
|
||||
|
||||
fn offerPage<'s>(&'s mut self, minsize: usize) -> &'s Self::Page {
|
||||
fn offerPage<'s>(&'s mut self, minsize: usize) -> Self::Page {
|
||||
return self
|
||||
.tryOfferPage(minsize)
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
}
|
||||
|
||||
fn tryOfferPage<'s>(&'s mut self, minimalSize: usize) -> Option<&'s Self::Page>;
|
||||
fn tryOfferPage<'s>(&'s mut self, minimalSize: usize) -> Option<Self::Page>;
|
||||
}
|
||||
|
||||
14
src/stack.rs
14
src/stack.rs
@ -1,25 +1,23 @@
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
pub unsafe trait StackHeap {
|
||||
pub unsafe trait StackHeap: Drop {
|
||||
fn childScope<'s>(&'s mut self) -> impl StackHeap;
|
||||
|
||||
fn alloc<'s, T: Sized>(&'s mut self, value: T) -> &'s mut T {
|
||||
return self
|
||||
.tryAlloc(value)
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
return self.tryAlloc(value).unwrap_or_else(|| crate::panicOOM());
|
||||
}
|
||||
fn allocUninitialized<'s, T: Sized>(&'s mut self) -> &'s mut MaybeUninit<T> {
|
||||
return self
|
||||
.tryAllocUninitialized()
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
.unwrap_or_else(|| crate::panicOOM());
|
||||
}
|
||||
fn allocZeroed<'s, T: Sized>(&'s mut self) -> &'s mut MaybeUninit<T> {
|
||||
return self
|
||||
.tryAllocZeroed()
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
return self.tryAllocZeroed().unwrap_or_else(|| crate::panicOOM());
|
||||
}
|
||||
|
||||
fn tryAlloc<'s, T: Sized>(&'s mut self, value: T) -> Option<&'s mut T>;
|
||||
fn tryAllocUninitialized<'s, T: Sized>(&'s mut self) -> Option<&'s mut MaybeUninit<T>>;
|
||||
fn tryAllocZeroed<'s, T: Sized>(&'s mut self) -> Option<&'s mut MaybeUninit<T>>;
|
||||
|
||||
fn dealloc<'s, T: Sized>(&'s mut self, p: &'s mut T);
|
||||
}
|
||||
|
||||
29
src/typed.rs
29
src/typed.rs
@ -1,28 +1,23 @@
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
pub unsafe trait TypedHeap<T: Sized> {
|
||||
type Dyn<_T: Sized>: crate::Dyn<_T>;
|
||||
|
||||
fn alloc<'s>(&'s mut self, value: T) -> Self::Dyn<T> {
|
||||
return self
|
||||
.tryAlloc(value)
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
pub unsafe trait TypedHeap<T: Sized>: Drop {
|
||||
fn alloc<'s>(&'s mut self, value: T) -> &'s mut T {
|
||||
return self.tryAlloc(value).unwrap_or_else(|| crate::panicOOM());
|
||||
}
|
||||
|
||||
fn allocUninitialized<'s>(&'s mut self) -> Self::Dyn<MaybeUninit<T>> {
|
||||
fn allocUninitialized<'s>(&'s mut self) -> &'s mut MaybeUninit<T> {
|
||||
return self
|
||||
.tryAllocUninitialized()
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
.unwrap_or_else(|| crate::panicOOM());
|
||||
}
|
||||
|
||||
fn allocZeroed<'s>(&'s mut self) -> Self::Dyn<MaybeUninit<T>> {
|
||||
return self
|
||||
.tryAllocZeroed()
|
||||
.unwrap_or_else(|| panic!("Out of memory"));
|
||||
fn allocZeroed<'s>(&'s mut self) -> &'s mut MaybeUninit<T> {
|
||||
return self.tryAllocZeroed().unwrap_or_else(|| crate::panicOOM());
|
||||
}
|
||||
|
||||
fn tryAlloc<'s>(&'s mut self, value: T) -> Option<Self::Dyn<T>>;
|
||||
fn tryAllocUninitialized<'s>(&'s mut self) -> Option<Self::Dyn<MaybeUninit<T>>>;
|
||||
fn tryAllocZeroed<'s>(&'s mut self) -> Option<Self::Dyn<MaybeUninit<T>>>;
|
||||
}
|
||||
fn tryAlloc<'s>(&'s mut self, value: T) -> Option<&'s mut T>;
|
||||
fn tryAllocUninitialized<'s>(&'s mut self) -> Option<&'s mut MaybeUninit<T>>;
|
||||
fn tryAllocZeroed<'s>(&'s mut self) -> Option<&'s mut MaybeUninit<T>>;
|
||||
|
||||
fn dealloc<'s>(&'s mut self, p: &'s mut T);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user