diff --git a/crates/context/interface/src/local.rs b/crates/context/interface/src/local.rs index 5367ab061f..56c4832842 100644 --- a/crates/context/interface/src/local.rs +++ b/crates/context/interface/src/local.rs @@ -3,12 +3,12 @@ use core::{ cell::{Ref, RefCell}, ops::Range, }; -use std::{boxed::Box, rc::Rc, vec::Vec}; +use std::{rc::Rc, vec::Vec}; /// Non-empty, item-pooling Vec. #[derive(Debug, Clone)] pub struct FrameStack { - stack: Vec>, + stack: Vec, index: Option, } @@ -20,10 +20,9 @@ impl Default for FrameStack { impl FrameStack { /// Creates a new, empty stack. It must be initialized with init before use. - #[inline] pub fn new() -> Self { Self { - stack: Vec::with_capacity(1025), + stack: Vec::with_capacity(4), index: None, } } @@ -102,19 +101,19 @@ impl FrameStack { /// A potentially initialized frame. Used when initializing a new frame in the main loop. #[allow(missing_debug_implementations)] pub struct OutFrame<'a, T> { - ptr: *mut Box, + ptr: *mut T, init: bool, lt: core::marker::PhantomData<&'a mut T>, } impl<'a, T> OutFrame<'a, T> { /// Creates a new initialized `OutFrame` from a mutable reference to a type `T`. - pub fn new_init(slot: &'a mut Box) -> Self { + pub fn new_init(slot: &'a mut T) -> Self { unsafe { Self::new_maybe_uninit(slot, true) } } /// Creates a new uninitialized `OutFrame` from a mutable reference to a `MaybeUninit`. - pub fn new_uninit(slot: &'a mut core::mem::MaybeUninit>) -> Self { + pub fn new_uninit(slot: &'a mut core::mem::MaybeUninit) -> Self { unsafe { Self::new_maybe_uninit(slot.as_mut_ptr(), false) } } @@ -125,7 +124,7 @@ impl<'a, T> OutFrame<'a, T> { /// This method is unsafe because it assumes that the pointer is valid and points to a location /// where a type `T` can be stored. It also assumes that the `init` flag correctly reflects whether /// the type `T` has been initialized or not. - pub unsafe fn new_maybe_uninit(ptr: *mut Box, init: bool) -> Self { + pub unsafe fn new_maybe_uninit(ptr: *mut T, init: bool) -> Self { Self { ptr, init, @@ -141,11 +140,12 @@ impl<'a, T> OutFrame<'a, T> { unsafe { &mut *self.ptr } } + #[inline(never)] #[cold] fn do_init(&mut self, f: impl FnOnce() -> T) { unsafe { self.init = true; - self.ptr.write(Box::new(f())); + self.ptr.write(f()); } } diff --git a/crates/interpreter/src/interpreter/ext_bytecode.rs b/crates/interpreter/src/interpreter/ext_bytecode.rs index 82e437a54f..ede6bfcb02 100644 --- a/crates/interpreter/src/interpreter/ext_bytecode.rs +++ b/crates/interpreter/src/interpreter/ext_bytecode.rs @@ -31,6 +31,7 @@ impl Deref for ExtBytecode { } impl Default for ExtBytecode { + #[inline] fn default() -> Self { Self::new(Bytecode::default()) } @@ -38,6 +39,7 @@ impl Default for ExtBytecode { impl ExtBytecode { /// Create new extended bytecode and set the instruction pointer to the start of the bytecode. + #[inline] pub fn new(base: Bytecode) -> Self { let instruction_pointer = base.bytecode_ptr(); Self {