optimize(value): less clone

This commit is contained in:
2025-05-22 21:24:19 +08:00
parent b0b73439fd
commit f380e5fd70
6 changed files with 105 additions and 106 deletions

View File

@@ -51,20 +51,12 @@ impl<T, const CAP: usize> Stack<T, CAP> {
unsafe { replace(item, MaybeUninit::uninit()).assume_init() }
}
pub fn tos(&self) -> Result<&T> {
if self.top == 0 {
panic!("stack empty")
} else {
Ok(into!(&self.items[self.top - 1]))
}
pub fn tos(&self) -> &T {
into!(&self.items[self.top - 1])
}
pub fn tos_mut(&mut self) -> Result<&mut T> {
if self.top == 0 {
panic!("stack empty")
} else {
Ok(into!(&mut self.items[self.top - 1]))
}
pub fn tos_mut(&mut self) -> &mut T {
into!(&mut self.items[self.top - 1])
}
}