Skip to content

Commit

Permalink
easier switching extend_from_within impl
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Apr 14, 2022
1 parent 2efd724 commit 30e65d7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/decoding/ringbuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl RingBuffer {

/// SAFETY:
/// Needs start + len <= self.len()
/// And more then len reserved space
#[warn(unsafe_op_in_unsafe_fn)]
pub unsafe fn extend_from_within_unchecked(&mut self, start: usize, len: usize) {
debug_assert!(self.buf != std::ptr::null_mut());
Expand Down Expand Up @@ -240,13 +241,10 @@ impl RingBuffer {
}

#[allow(dead_code)]
pub fn extend_from_within_branchless(&mut self, start: usize, len: usize) {
if start > self.len() || start + len > self.len() {
panic!("This is illegal!");
}

self.reserve(len);

/// SAFETY:
/// Needs start + len <= self.len()
/// And more then len reserved space
pub unsafe fn extend_from_within_unchecked_branchless(&mut self, start: usize, len: usize) {
// data slices in raw parts
let ((s1_ptr, s1_len), (s2_ptr, s2_len)) = self.data_slice_parts();

Expand Down

0 comments on commit 30e65d7

Please sign in to comment.