Skip to content

Commit 3ff9e74

Browse files
committed
Change inlining in RngCore implementation for references
1 parent 5641c0d commit 3ff9e74

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
@@ -385,7 +385,9 @@ pub trait SeedableRng: Sized {
385385
}
386386
}
387387

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

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

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

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

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

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

0 commit comments

Comments
 (0)