From 2a1806abe83d71dc4b9be23939146217b12661ac Mon Sep 17 00:00:00 2001 From: Alexey Gerasev Date: Tue, 17 Jan 2023 13:11:27 +0700 Subject: [PATCH] Rename underscored methods --- src/consumer.rs | 6 +++--- src/producer.rs | 2 +- src/ring_buffer/base.rs | 22 +++++++++++----------- src/ring_buffer/cache.rs | 8 ++++---- src/ring_buffer/local.rs | 2 +- src/ring_buffer/rb.rs | 6 +++--- src/ring_buffer/shared.rs | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/consumer.rs b/src/consumer.rs index 79f9ace..631741b 100644 --- a/src/consumer.rs +++ b/src/consumer.rs @@ -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. @@ -235,7 +235,7 @@ 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 } @@ -243,7 +243,7 @@ assert_eq!(cons.skip(8), 0); /// /// Returns the number of deleted items. pub fn clear(&mut self) -> usize { - unsafe { self.target.__skip(None) } + unsafe { self.target.skip_internal(None) } } } diff --git a/src/producer.rs b/src/producer.rs index 8d86efb..dc048e8 100644 --- a/src/producer.rs +++ b/src/producer.rs @@ -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. diff --git a/src/ring_buffer/base.rs b/src/ring_buffer/base.rs index 803060d..0f65a52 100644 --- a/src/ring_buffer/base.rs +++ b/src/ring_buffer/base.rs @@ -31,7 +31,7 @@ pub trait RbBase { /// 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; @@ -43,20 +43,20 @@ pub trait RbBase { /// /// 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. @@ -94,14 +94,14 @@ pub trait RbRead: RbBase { /// *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, Range) { 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); @@ -146,7 +146,7 @@ pub trait RbRead: RbBase { /// # Safety /// /// Must not be called concurrently. - unsafe fn __skip(&self, count_or_all: Option) -> usize { + unsafe fn skip_internal(&self, count_or_all: Option) -> usize { let (left, right) = self.occupied_slices(); let count = match count_or_all { Some(count) => { @@ -187,14 +187,14 @@ pub trait RbWrite: RbBase { /// *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, Range) { 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); diff --git a/src/ring_buffer/cache.rs b/src/ring_buffer/cache.rs index d182db7..bfeac97 100644 --- a/src/ring_buffer/cache.rs +++ b/src/ring_buffer/cache.rs @@ -43,8 +43,8 @@ where } #[inline] - fn __capacity(&self) -> NonZeroUsize { - self.target.__capacity() + fn capacity_nonzero(&self) -> NonZeroUsize { + self.target.capacity_nonzero() } #[inline] @@ -68,8 +68,8 @@ where } #[inline] - fn __capacity(&self) -> NonZeroUsize { - self.target.__capacity() + fn capacity_nonzero(&self) -> NonZeroUsize { + self.target.capacity_nonzero() } #[inline] diff --git a/src/ring_buffer/local.rs b/src/ring_buffer/local.rs index b3d6764..9c99f63 100644 --- a/src/ring_buffer/local.rs +++ b/src/ring_buffer/local.rs @@ -48,7 +48,7 @@ impl> RbBase for LocalRb { } #[inline] - fn __capacity(&self) -> NonZeroUsize { + fn capacity_nonzero(&self) -> NonZeroUsize { self.storage.len() } diff --git a/src/ring_buffer/rb.rs b/src/ring_buffer/rb.rs index fedbe2e..30b5e93 100644 --- a/src/ring_buffer/rb.rs +++ b/src/ring_buffer/rb.rs @@ -28,7 +28,7 @@ pub trait Rb: RbRead + RbWrite { /// The capacity of the buffer is constant. #[inline] fn capacity(&self) -> usize { - >::__capacity(self).get() + >::capacity_nonzero(self).get() } /// The number of items stored in the ring buffer. @@ -94,7 +94,7 @@ pub trait Rb: RbRead + RbWrite { /// *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 } @@ -103,7 +103,7 @@ pub trait Rb: RbRead + RbWrite { /// 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. diff --git a/src/ring_buffer/shared.rs b/src/ring_buffer/shared.rs index 1cb7efd..fab1783 100644 --- a/src/ring_buffer/shared.rs +++ b/src/ring_buffer/shared.rs @@ -49,7 +49,7 @@ impl> RbBase for SharedRb { } #[inline] - fn __capacity(&self) -> NonZeroUsize { + fn capacity_nonzero(&self) -> NonZeroUsize { self.storage.len() }