Skip to content

Commit b4d3035

Browse files
wip
1 parent 6993dc2 commit b4d3035

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/decoding/ringbuffer.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use core::{cmp, hint::unreachable_unchecked, iter, mem::MaybeUninit, slice};
2-
use std::collections::VecDeque;
1+
use alloc::collections::VecDeque;
2+
use core::{cmp, hint::unreachable_unchecked, mem::MaybeUninit, slice};
33

44
pub struct RingBuffer {
55
buf: VecDeque<MaybeUninit<u8>>,
@@ -80,9 +80,7 @@ impl RingBuffer {
8080
pub fn extend(&mut self, data: &[u8]) {
8181
let len = data.len();
8282
let data = data.as_ptr().cast::<MaybeUninit<u8>>();
83-
let data = unsafe {
84-
slice::from_raw_parts(data, len)
85-
};
83+
let data = unsafe { slice::from_raw_parts(data, len) };
8684
self.buf.extend(data);
8785
}
8886

@@ -160,7 +158,7 @@ impl RingBuffer {
160158
let skip = cmp::min(a.len(), start);
161159
start -= skip;
162160
let a = &a[skip..];
163-
let b = &b[start..];
161+
let b = unsafe { b.get_unchecked(start..) };
164162

165163
let mut remaining_copy_len = len;
166164

@@ -169,7 +167,7 @@ impl RingBuffer {
169167
copy_bytes_overshooting(a, a_spare, copy_at_least);
170168
remaining_copy_len -= copy_at_least;
171169

172-
if remaining_copy_len==0{
170+
if remaining_copy_len == 0 {
173171
intermediate.disarmed = true;
174172
return;
175173
}
@@ -182,7 +180,7 @@ impl RingBuffer {
182180
copy_bytes_overshooting(a, b_spare, copy_at_least);
183181
remaining_copy_len -= copy_at_least;
184182

185-
if remaining_copy_len==0{
183+
if remaining_copy_len == 0 {
186184
intermediate.disarmed = true;
187185
return;
188186
}
@@ -194,7 +192,7 @@ impl RingBuffer {
194192
copy_bytes_overshooting(b, a_spare, copy_at_least);
195193
remaining_copy_len -= copy_at_least;
196194

197-
if remaining_copy_len==0{
195+
if remaining_copy_len == 0 {
198196
intermediate.disarmed = true;
199197
return;
200198
}
@@ -232,8 +230,8 @@ impl<'a> IntermediateRingBuffer<'a> {
232230
let b_mid = remaining_init_len;
233231
debug_assert!(b.len() >= b_mid);
234232

235-
let (a, a_spare) = a.split_at_mut(a_mid);
236-
let (b, b_spare) = b.split_at_mut(b_mid);
233+
let (a, a_spare) = unsafe { a.split_at_mut_unchecked(a_mid) };
234+
let (b, b_spare) = unsafe { b.split_at_mut_unchecked(b_mid) };
237235
debug_assert!(a_spare.is_empty() || b.is_empty());
238236

239237
(

0 commit comments

Comments
 (0)