Skip to content

Commit

Permalink
Modify inline hints
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Mar 4, 2018
1 parent dd398a6 commit c3c1eec
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
18 changes: 8 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,45 +726,41 @@ pub trait Rng: RngCore + Sized {
impl<R: RngCore> Rng for R {}

impl<'a, R: RngCore + ?Sized> RngCore for &'a mut R {
#[inline]
#[inline(always)]
fn next_u32(&mut self) -> u32 {
(**self).next_u32()
}

#[inline]
#[inline(always)]
fn next_u64(&mut self) -> u64 {
(**self).next_u64()
}

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
(**self).fill_bytes(dest)
}

#[inline]

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
(**self).try_fill_bytes(dest)
}
}

#[cfg(any(feature="std", feature="alloc"))]
impl<R: RngCore + ?Sized> RngCore for Box<R> {
#[inline]
#[inline(always)]
fn next_u32(&mut self) -> u32 {
(**self).next_u32()
}

#[inline]
#[inline(always)]
fn next_u64(&mut self) -> u64 {
(**self).next_u64()
}

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
(**self).fill_bytes(dest)
}

#[inline]

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
(**self).try_fill_bytes(dest)
}
Expand Down Expand Up @@ -1028,10 +1024,12 @@ pub trait BlockRngCore<T>: Sized {
pub struct StdRng(Hc128Rng);

impl RngCore for StdRng {
#[inline(always)]
fn next_u32(&mut self) -> u32 {
self.0.next_u32()
}

#[inline(always)]
fn next_u64(&mut self) -> u64 {
self.0.next_u64()
}
Expand Down
6 changes: 2 additions & 4 deletions src/prng/hc128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,20 @@ const SEED_WORDS: usize = 8; // 128 bit key followed by 128 bit iv
pub struct Hc128Rng(BlockRng<Hc128Core>);

impl RngCore for Hc128Rng {
#[inline]
#[inline(always)]
fn next_u32(&mut self) -> u32 {
self.0.next_u32()
}

#[inline]
#[inline(always)]
fn next_u64(&mut self) -> u64 {
self.0.next_u64()
}

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
self.0.fill_bytes(dest)
}

#[inline]
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
self.0.try_fill_bytes(dest)
}
Expand Down
6 changes: 2 additions & 4 deletions src/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,20 @@ where R: BlockRngCore<u32> + SeedableRng,
}

impl<R: BlockRngCore<u32> + SeedableRng, Rsdr: RngCore> RngCore for ReseedingRng<R, Rsdr> {
#[inline]
#[inline(always)]
fn next_u32(&mut self) -> u32 {
self.0.next_u32()
}

#[inline]
#[inline(always)]
fn next_u64(&mut self) -> u64 {
self.0.next_u64()
}

#[inline]
fn fill_bytes(&mut self, dest: &mut [u8]) {
self.0.fill_bytes(dest)
}

#[inline]
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
self.0.try_fill_bytes(dest)
}
Expand Down
8 changes: 3 additions & 5 deletions src/thread_rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,20 @@ pub fn thread_rng() -> ThreadRng {
}

impl RngCore for ThreadRng {
#[inline]
#[inline(always)]
fn next_u32(&mut self) -> u32 {
self.rng.borrow_mut().next_u32()
}

#[inline]
#[inline(always)]
fn next_u64(&mut self) -> u64 {
self.rng.borrow_mut().next_u64()
}

#[inline]
fn fill_bytes(&mut self, bytes: &mut [u8]) {
self.rng.borrow_mut().fill_bytes(bytes)
}

#[inline]

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
self.rng.borrow_mut().try_fill_bytes(dest)
}
Expand Down

0 comments on commit c3c1eec

Please sign in to comment.