Skip to content

Commit

Permalink
mark some size functions const (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalamay authored Mar 14, 2024
1 parent 90ec625 commit 8a6e15f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl Size {
/// assert_eq!(size.round(sys+1), sys*2); // probably 8192
/// ```
#[inline]
pub fn round(&self, len: usize) -> usize {
pub const fn round(&self, len: usize) -> usize {
self.truncate(len + self.0 - 1)
}

Expand All @@ -382,7 +382,7 @@ impl Size {
/// assert_eq!(size.truncate(sys+1), sys); // probably 4096
/// ```
#[inline]
pub fn truncate(&self, len: usize) -> usize {
pub const fn truncate(&self, len: usize) -> usize {
len & !(self.0 - 1)
}

Expand All @@ -400,7 +400,7 @@ impl Size {
/// assert_eq!(size.offset(sys*2 + 123), 123);
/// ```
#[inline]
pub fn offset(&self, len: usize) -> usize {
pub const fn offset(&self, len: usize) -> usize {
len & (self.0 - 1)
}

Expand All @@ -418,7 +418,7 @@ impl Size {
/// assert_eq!(size.size(2), sys*2); // probably 8192
/// ```
#[inline]
pub fn size(&self, count: u32) -> usize {
pub const fn size(&self, count: u32) -> usize {
(count as usize) << self.0.trailing_zeros()
}

Expand All @@ -439,7 +439,7 @@ impl Size {
/// assert_eq!(size.count(sys*2), 2);
/// ```
#[inline]
pub fn count(&self, len: usize) -> u32 {
pub const fn count(&self, len: usize) -> u32 {
(self.round(len) >> self.0.trailing_zeros()) as u32
}

Expand Down

0 comments on commit 8a6e15f

Please sign in to comment.