Skip to content

Commit

Permalink
Rename underscored methods
Browse files Browse the repository at this point in the history
  • Loading branch information
agerasev committed Jan 17, 2023
1 parent f903b95 commit 2a1806a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ where
/// The capacity of the buffer is constant.
#[inline]
pub fn capacity(&self) -> usize {
self.target.__capacity().get()
self.target.capacity_nonzero().get()
}

/// Checks if the ring buffer is empty.
Expand Down Expand Up @@ -235,15 +235,15 @@ assert_eq!(cons.skip(8), 0);
)]
pub fn skip(&mut self, count: usize) -> usize {
let count = cmp::min(count, self.len());
assert_eq!(unsafe { self.target.__skip(Some(count)) }, count);
assert_eq!(unsafe { self.target.skip_internal(Some(count)) }, count);
count
}

/// Removes all items from the buffer and safely drops them.
///
/// Returns the number of deleted items.
pub fn clear(&mut self) -> usize {
unsafe { self.target.__skip(None) }
unsafe { self.target.skip_internal(None) }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where
/// The capacity of the buffer is constant.
#[inline]
pub fn capacity(&self) -> usize {
self.target.__capacity().get()
self.target.capacity_nonzero().get()
}

/// Checks if the ring buffer is empty.
Expand Down
22 changes: 11 additions & 11 deletions src/ring_buffer/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait RbBase<T> {
/// Capacity of the ring buffer.
///
/// It is constant during the whole ring buffer lifetime.
fn __capacity(&self) -> NonZeroUsize;
fn capacity_nonzero(&self) -> NonZeroUsize;

/// Head position.
fn head(&self) -> usize;
Expand All @@ -43,20 +43,20 @@ pub trait RbBase<T> {
///
/// Equals to `2 * len`.
#[inline]
fn __modulus(&self) -> NonZeroUsize {
unsafe { NonZeroUsize::new_unchecked(2 * self.__capacity().get()) }
fn modulus(&self) -> NonZeroUsize {
unsafe { NonZeroUsize::new_unchecked(2 * self.capacity_nonzero().get()) }
}

/// The number of items stored in the buffer at the moment.
fn occupied_len(&self) -> usize {
let modulus = self.__modulus();
let modulus = self.modulus();
(modulus.get() + self.tail() - self.head()) % modulus
}

/// The number of vacant places in the buffer at the moment.
fn vacant_len(&self) -> usize {
let modulus = self.__modulus();
(self.__capacity().get() + self.head() - self.tail()) % modulus
let modulus = self.modulus();
(self.capacity_nonzero().get() + self.head() - self.tail()) % modulus
}

/// Checks if the occupied range is empty.
Expand Down Expand Up @@ -94,14 +94,14 @@ pub trait RbRead<T>: RbBase<T> {
/// *In debug mode panics if `count` is greater than number of items in the ring buffer.*
unsafe fn advance_head(&self, count: usize) {
debug_assert!(count <= self.occupied_len());
self.set_head((self.head() + count) % self.__modulus());
self.set_head((self.head() + count) % self.modulus());
}

/// Returns a pair of ranges of [`Self::occupied_slices`] location in underlying container.
fn occupied_ranges(&self) -> (Range<usize>, Range<usize>) {
let head = self.head();
let tail = self.tail();
let len = self.__capacity();
let len = self.capacity_nonzero();

let (head_div, head_mod) = (head / len, head % len);
let (tail_div, tail_mod) = (tail / len, tail % len);
Expand Down Expand Up @@ -146,7 +146,7 @@ pub trait RbRead<T>: RbBase<T> {
/// # Safety
///
/// Must not be called concurrently.
unsafe fn __skip(&self, count_or_all: Option<usize>) -> usize {
unsafe fn skip_internal(&self, count_or_all: Option<usize>) -> usize {
let (left, right) = self.occupied_slices();
let count = match count_or_all {
Some(count) => {
Expand Down Expand Up @@ -187,14 +187,14 @@ pub trait RbWrite<T>: RbBase<T> {
/// *In debug mode panics if `count` is greater than number of vacant places in the ring buffer.*
unsafe fn advance_tail(&self, count: usize) {
debug_assert!(count <= self.vacant_len());
self.set_tail((self.tail() + count) % self.__modulus());
self.set_tail((self.tail() + count) % self.modulus());
}

/// Returns a pair of ranges of [`Self::vacant_slices`] location in underlying container.
fn vacant_ranges(&self) -> (Range<usize>, Range<usize>) {
let head = self.head();
let tail = self.tail();
let len = self.__capacity();
let len = self.capacity_nonzero();

let (head_div, head_mod) = (head / len, head % len);
let (tail_div, tail_mod) = (tail / len, tail % len);
Expand Down
8 changes: 4 additions & 4 deletions src/ring_buffer/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ where
}

#[inline]
fn __capacity(&self) -> NonZeroUsize {
self.target.__capacity()
fn capacity_nonzero(&self) -> NonZeroUsize {
self.target.capacity_nonzero()
}

#[inline]
Expand All @@ -68,8 +68,8 @@ where
}

#[inline]
fn __capacity(&self) -> NonZeroUsize {
self.target.__capacity()
fn capacity_nonzero(&self) -> NonZeroUsize {
self.target.capacity_nonzero()
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/ring_buffer/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<T, C: Container<T>> RbBase<T> for LocalRb<T, C> {
}

#[inline]
fn __capacity(&self) -> NonZeroUsize {
fn capacity_nonzero(&self) -> NonZeroUsize {
self.storage.len()
}

Expand Down
6 changes: 3 additions & 3 deletions src/ring_buffer/rb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait Rb<T>: RbRead<T> + RbWrite<T> {
/// The capacity of the buffer is constant.
#[inline]
fn capacity(&self) -> usize {
<Self as RbBase<T>>::__capacity(self).get()
<Self as RbBase<T>>::capacity_nonzero(self).get()
}

/// The number of items stored in the ring buffer.
Expand Down Expand Up @@ -94,7 +94,7 @@ pub trait Rb<T>: RbRead<T> + RbWrite<T> {
/// *Panics if `n` is greater than number of items in the ring buffer.*
fn skip(&mut self, count: usize) -> usize {
assert!(count <= self.len());
unsafe { self.__skip(Some(count)) };
unsafe { self.skip_internal(Some(count)) };
count
}

Expand All @@ -103,7 +103,7 @@ pub trait Rb<T>: RbRead<T> + RbWrite<T> {
/// Returns the number of deleted items.
#[inline]
fn clear(&mut self) -> usize {
unsafe { self.__skip(None) }
unsafe { self.skip_internal(None) }
}

/// Appends an item to the ring buffer.
Expand Down
2 changes: 1 addition & 1 deletion src/ring_buffer/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<T, C: Container<T>> RbBase<T> for SharedRb<T, C> {
}

#[inline]
fn __capacity(&self) -> NonZeroUsize {
fn capacity_nonzero(&self) -> NonZeroUsize {
self.storage.len()
}

Expand Down

0 comments on commit 2a1806a

Please sign in to comment.