Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,19 @@ macro_rules! construct_fixed_hash {
impl $name {
/// Returns a new fixed hash where all bits are set to the given byte.
#[inline]
pub fn repeat_byte(byte: u8) -> $name {
pub const fn repeat_byte(byte: u8) -> $name {
$name([byte; $n_bytes])
}

/// Returns a new zero-initialized fixed hash.
#[inline]
pub fn zero() -> $name {
pub const fn zero() -> $name {
$name::repeat_byte(0u8)
}

/// Returns the size of this hash in bytes.
#[inline]
pub fn len_bytes() -> usize {
pub const fn len_bytes() -> usize {
$n_bytes
}

Expand All @@ -137,7 +137,7 @@ macro_rules! construct_fixed_hash {

/// Extracts a reference to the byte array containing the entire fixed hash.
#[inline]
pub fn as_fixed_bytes(&self) -> &[u8; $n_bytes] {
pub const fn as_fixed_bytes(&self) -> &[u8; $n_bytes] {
&self.0
}

Expand All @@ -149,7 +149,7 @@ macro_rules! construct_fixed_hash {

/// Returns the inner bytes array.
#[inline]
pub fn to_fixed_bytes(self) -> [u8; $n_bytes] {
pub const fn to_fixed_bytes(self) -> [u8; $n_bytes] {
self.0
}

Expand Down
8 changes: 4 additions & 4 deletions rlp/src/rlpin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct OffsetCache {
}

impl OffsetCache {
fn new(index: usize, offset: usize) -> OffsetCache {
const fn new(index: usize, offset: usize) -> OffsetCache {
OffsetCache { index, offset }
}
}
Expand Down Expand Up @@ -68,7 +68,7 @@ fn calculate_payload_info(header_bytes: &[u8], len_of_len: usize) -> Result<Payl
}

impl PayloadInfo {
fn new(header_len: usize, value_len: usize) -> PayloadInfo {
const fn new(header_len: usize, value_len: usize) -> PayloadInfo {
PayloadInfo { header_len, value_len }
}

Expand Down Expand Up @@ -128,7 +128,7 @@ impl<'a> fmt::Display for Rlp<'a> {
}

impl<'a> Rlp<'a> {
pub fn new(bytes: &'a [u8]) -> Rlp<'a> {
pub const fn new(bytes: &'a [u8]) -> Rlp<'a> {
Rlp { bytes, offset_cache: Cell::new(None), count_cache: Cell::new(None) }
}

Expand Down Expand Up @@ -374,7 +374,7 @@ pub struct BasicDecoder<'a> {
}

impl<'a> BasicDecoder<'a> {
pub fn new(rlp: &'a [u8]) -> BasicDecoder<'a> {
pub const fn new(rlp: &'a [u8]) -> BasicDecoder<'a> {
BasicDecoder { rlp }
}

Expand Down
18 changes: 9 additions & 9 deletions uint/src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ macro_rules! construct_uint {
impl $name {
/// Low 2 words (u128)
#[inline]
pub fn low_u128(&self) -> u128 {
pub const fn low_u128(&self) -> u128 {
let &$name(ref arr) = self;
((arr[1] as u128) << 64) + arr[0] as u128
}
Expand Down Expand Up @@ -473,14 +473,14 @@ macro_rules! construct_uint {

/// Conversion to u32
#[inline]
pub fn low_u32(&self) -> u32 {
pub const fn low_u32(&self) -> u32 {
let &$name(ref arr) = self;
arr[0] as u32
}

/// Low word (u64)
#[inline]
pub fn low_u64(&self) -> u64 {
pub const fn low_u64(&self) -> u64 {
let &$name(ref arr) = self;
arr[0]
}
Expand Down Expand Up @@ -560,7 +560,7 @@ macro_rules! construct_uint {
///
/// Panics if `index` exceeds the bit width of the number.
#[inline]
pub fn bit(&self, index: usize) -> bool {
pub const fn bit(&self, index: usize) -> bool {
let &$name(ref arr) = self;
arr[index / 64] & (1 << (index % 64)) != 0
}
Expand Down Expand Up @@ -601,7 +601,7 @@ macro_rules! construct_uint {
///
/// Panics if `index` exceeds the byte width of the number.
#[inline]
pub fn byte(&self, index: usize) -> u8 {
pub const fn byte(&self, index: usize) -> u8 {
let &$name(ref arr) = self;
(arr[index / 8] >> (((index % 8)) * 8)) as u8
}
Expand Down Expand Up @@ -1066,18 +1066,18 @@ macro_rules! construct_uint {
}

#[inline(always)]
fn mul_u64(a: u64, b: u64, carry: u64) -> (u64, u64) {
let (hi, lo) = Self::split_u128(u128::from(a) * u128::from(b) + u128::from(carry));
const fn mul_u64(a: u64, b: u64, carry: u64) -> (u64, u64) {
let (hi, lo) = Self::split_u128(a as u128 * b as u128 + carry as u128);
(lo, hi)
}

#[inline(always)]
fn split(a: u64) -> (u64, u64) {
const fn split(a: u64) -> (u64, u64) {
(a >> 32, a & 0xFFFF_FFFF)
}

#[inline(always)]
fn split_u128(a: u128) -> (u64, u64) {
const fn split_u128(a: u128) -> (u64, u64) {
((a >> 64) as _, (a & 0xFFFFFFFFFFFFFFFF) as _)
}

Expand Down