Skip to content

Commit 2cb0555

Browse files
authored
Merge pull request #401 from pitdicker/fill_bytes_inlining
Change inlining in RngCore implementation for references
2 parents 7b14992 + 3ff9e74 commit 2cb0555

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

rand_core/src/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,9 @@ pub trait SeedableRng: Sized {
386386
}
387387
}
388388

389-
389+
// Implement `RngCore` for references to an `RngCore`.
390+
// Force inlining all functions, so that it is up to the `RngCore`
391+
// implementation and the optimizer to decide on inlining.
390392
impl<'a, R: RngCore + ?Sized> RngCore for &'a mut R {
391393
#[inline(always)]
392394
fn next_u32(&mut self) -> u32 {
@@ -398,15 +400,20 @@ impl<'a, R: RngCore + ?Sized> RngCore for &'a mut R {
398400
(**self).next_u64()
399401
}
400402

403+
#[inline(always)]
401404
fn fill_bytes(&mut self, dest: &mut [u8]) {
402405
(**self).fill_bytes(dest)
403406
}
404407

408+
#[inline(always)]
405409
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
406410
(**self).try_fill_bytes(dest)
407411
}
408412
}
409413

414+
// Implement `RngCore` for boxed references to an `RngCore`.
415+
// Force inlining all functions, so that it is up to the `RngCore`
416+
// implementation and the optimizer to decide on inlining.
410417
#[cfg(feature="alloc")]
411418
impl<R: RngCore + ?Sized> RngCore for Box<R> {
412419
#[inline(always)]
@@ -419,10 +426,12 @@ impl<R: RngCore + ?Sized> RngCore for Box<R> {
419426
(**self).next_u64()
420427
}
421428

429+
#[inline(always)]
422430
fn fill_bytes(&mut self, dest: &mut [u8]) {
423431
(**self).fill_bytes(dest)
424432
}
425433

434+
#[inline(always)]
426435
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
427436
(**self).try_fill_bytes(dest)
428437
}

0 commit comments

Comments
 (0)