Skip to content

Commit

Permalink
Merge pull request #401 from pitdicker/fill_bytes_inlining
Browse files Browse the repository at this point in the history
Change inlining in RngCore implementation for references
  • Loading branch information
dhardy authored Apr 16, 2018
2 parents 7b14992 + 3ff9e74 commit 2cb0555
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 @@ -386,7 +386,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 @@ -398,15 +400,20 @@ 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)
}
}

// 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 @@ -419,10 +426,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 2cb0555

Please sign in to comment.