Skip to content

Commit 1745287

Browse files
committed
Change inlining in RngCore implementation for references
1 parent e53fc14 commit 1745287

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

rand_core/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,9 @@ pub trait SeedableRng: Sized {
397397
}
398398
}
399399

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

414+
#[inline(always)]
412415
fn fill_bytes(&mut self, dest: &mut [u8]) {
413416
(**self).fill_bytes(dest)
414417
}
415418

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

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

444+
#[inline(always)]
437445
fn fill_bytes(&mut self, dest: &mut [u8]) {
438446
(**self).fill_bytes(dest)
439447
}
440448

449+
#[inline(always)]
441450
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> {
442451
(**self).try_fill_bytes(dest)
443452
}

0 commit comments

Comments
 (0)