Skip to content

Commit

Permalink
Change inlining in RngCore implementation for references
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Apr 12, 2018
1 parent e53fc14 commit 1745287
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ pub trait SeedableRng: Sized {
}
}


// Implement `RngCore` for references to an `RngCore`.
// Force inlining all functions, so that it is up to the `RngCore`
// implementation and the optimizer to decide on inlining.
impl<'a, R: RngCore + ?Sized> RngCore for &'a mut R {
#[inline(always)]
fn next_u32(&mut self) -> u32 {
Expand All @@ -409,10 +411,12 @@ impl<'a, R: RngCore + ?Sized> RngCore for &'a mut R {
(**self).next_u64()
}

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

#[inline(always)]
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
(**self).try_fill_bytes(dest)
}
Expand All @@ -422,6 +426,9 @@ impl<'a, R: RngCore + ?Sized> RngCore for &'a mut R {
}
}

// Implement `RngCore` for boxed references to an `RngCore`.
// Force inlining all functions, so that it is up to the `RngCore`
// implementation and the optimizer to decide on inlining.
#[cfg(feature="alloc")]
impl<R: RngCore + ?Sized> RngCore for Box<R> {
#[inline(always)]
Expand All @@ -434,10 +441,12 @@ impl<R: RngCore + ?Sized> RngCore for Box<R> {
(**self).next_u64()
}

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

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

0 comments on commit 1745287

Please sign in to comment.