From 17452876baac7fb182225603d0c73554075bfa75 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Sat, 7 Apr 2018 17:01:47 +0200 Subject: [PATCH] Change inlining in RngCore implementation for references --- rand_core/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rand_core/src/lib.rs b/rand_core/src/lib.rs index c06c69ccd7a..1e6b158e506 100644 --- a/rand_core/src/lib.rs +++ b/rand_core/src/lib.rs @@ -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 { @@ -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) } @@ -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 RngCore for Box { #[inline(always)] @@ -434,10 +441,12 @@ impl RngCore for Box { (**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) }