From 36e4b129343940ee4d91ffd3e997ec8d3515aed9 Mon Sep 17 00:00:00 2001 From: xavo95 Date: Sun, 12 Jan 2025 19:28:45 +0100 Subject: [PATCH] Improvements --- src/t_array.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/t_array.rs b/src/t_array.rs index 1d5b4c0..cc60c94 100644 --- a/src/t_array.rs +++ b/src/t_array.rs @@ -36,6 +36,20 @@ impl TArray { } } + pub fn capacity(&self) -> u32 { + self.cap + } + + pub fn clear(&mut self, len: u32) -> Self { + if self.data_ptr != 0 && self.len > 0 { + let data = unsafe { + std::slice::from_raw_parts_mut(self.data_ptr as *mut u8, self.len) + }; + data.fill(0); + self.len = 0; + } + } + #[inline(always)] pub(crate) fn resize_grow(&mut self, count: Option) -> u32 { let count = count.unwrap_or(1);