Refactor terminator pop

This commit is contained in:
Yota Toyama 2025-04-06 20:54:40 -07:00
parent 424f5ab39c
commit fb8525bad4

View File

@ -223,13 +223,9 @@ impl<const N: usize> CString<N> {
/// # Safety: caller must ensure to re-add the terminator after this function is called /// # Safety: caller must ensure to re-add the terminator after this function is called
#[inline] #[inline]
unsafe fn pop_terminator(&mut self) { unsafe fn pop_terminator(&mut self) {
if cfg!(debug_assertions) { debug_assert_eq!(self.vec.last(), Some(&0));
let popped = self.vec.pop();
assert_eq!(popped, Some(0)); unsafe { self.vec.pop_unchecked() };
} else {
unsafe { self.vec.pop_unchecked() };
}
} }
/// Converts a [`CString`] to a string slice without checking /// Converts a [`CString`] to a string slice without checking