Skip to content

Commit f833a92

Browse files
committed
fix: remove unsafe drain
Has performance penalty because allocation is not reused
1 parent ef00b81 commit f833a92

File tree

1 file changed

+1
-35
lines changed

1 file changed

+1
-35
lines changed

crates/hyperion/src/storage/thread_local.rs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<T> ThreadHeaplessVec<T> {
189189
self.inner
190190
.iter_mut()
191191
.map(SyncUnsafeCell::get_mut)
192-
.flat_map(|inner| Drain::new(inner))
192+
.flat_map(|inner| std::mem::take(inner).into_iter())
193193
}
194194

195195
pub fn is_empty(&mut self) -> bool {
@@ -199,37 +199,3 @@ impl<T> ThreadHeaplessVec<T> {
199199
.all(|x| x.is_empty())
200200
}
201201
}
202-
203-
struct Drain<'a, T, const N: usize> {
204-
inner: &'a mut heapless::Vec<T, N>,
205-
idx: usize,
206-
}
207-
208-
impl<T, const N: usize> Iterator for Drain<'_, T, N> {
209-
type Item = T;
210-
211-
fn next(&mut self) -> Option<Self::Item> {
212-
if self.idx >= self.inner.len() {
213-
return None;
214-
}
215-
216-
let item = self.inner.get(self.idx).unwrap();
217-
let item = unsafe { core::ptr::read(item) };
218-
219-
self.idx += 1;
220-
221-
Some(item)
222-
}
223-
}
224-
225-
impl<T, const N: usize> Drop for Drain<'_, T, N> {
226-
fn drop(&mut self) {
227-
unsafe { self.inner.set_len(0) };
228-
}
229-
}
230-
231-
impl<'a, T, const N: usize> Drain<'a, T, N> {
232-
pub fn new(inner: &'a mut heapless::Vec<T, N>) -> Self {
233-
Self { inner, idx: 0 }
234-
}
235-
}

0 commit comments

Comments
 (0)