Skip to content

Commit

Permalink
feat: const-ify read methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluefinger committed Feb 27, 2024
1 parent f007f2f commit ba5d5bd
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/hasher/read.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#[inline(always)]
pub(super) fn wyread64(bits: &[u8]) -> u64 {
u64::from(bits[7]) << 56
| u64::from(bits[6]) << 48
| u64::from(bits[5]) << 40
| u64::from(bits[4]) << 32
| u64::from(bits[3]) << 24
| u64::from(bits[2]) << 16
| u64::from(bits[1]) << 8
| u64::from(bits[0])
pub(super) const fn wyread64(bits: &[u8]) -> u64 {
(bits[7] as u64) << 56
| (bits[6] as u64) << 48
| (bits[5] as u64) << 40
| (bits[4] as u64) << 32
| (bits[3] as u64) << 24
| (bits[2] as u64) << 16
| (bits[1] as u64) << 8
| (bits[0] as u64)
}

#[inline(always)]
pub(super) fn wyread32(bits: &[u8]) -> u64 {
u64::from(bits[3]) << 24
| u64::from(bits[2]) << 16
| u64::from(bits[1]) << 8
| u64::from(bits[0])
pub(super) const fn wyread32(bits: &[u8]) -> u64 {
(bits[3] as u64) << 24
| (bits[2] as u64) << 16
| (bits[1] as u64) << 8
| (bits[0] as u64)
}

#[inline(always)]
pub(super) fn wyread_upto_24(bits: &[u8]) -> u64 {
u64::from(bits[0]) << 16
| u64::from(bits[bits.len() >> 1]) << 8
| u64::from(bits[bits.len() - 1])
pub(super) const fn wyread_upto_24(bits: &[u8]) -> u64 {
(bits[0] as u64) << 16
| (bits[bits.len() >> 1] as u64) << 8
| (bits[bits.len() - 1] as u64)
}

#[inline(always)]
pub(super) fn is_over_48_bytes(length: usize) -> bool {
pub(super) const fn is_over_48_bytes(length: usize) -> bool {
#[cfg(feature = "v4_2")]
{
length >= 48
Expand Down

0 comments on commit ba5d5bd

Please sign in to comment.