-
-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add read_adapter to avoid dynamic dispatch #1267
Conversation
rand_core/src/lib.rs
Outdated
@@ -470,13 +477,45 @@ impl<R: RngCore + ?Sized> RngCore for Box<R> { | |||
} | |||
|
|||
#[cfg(feature = "std")] | |||
#[deprecated = "Use rng.read_adapter() instead."] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there are any cases where you couldn't use the read_adapter?
Can you give an example where this improves benchmark results? |
I forgot to mention that using dyn is also just plain annoying: group.bench_function("dyn-on", |b| {
b.iter_with_setup(
|| Xoshiro256PlusPlus::seed_from_u64(42),
|mut rand| {
io::copy(
&mut (&mut rand as &mut dyn RngCore).take(100),
&mut io::sink(),
)
},
);
});
group.bench_function("dyn-off", |b| {
b.iter_with_setup(
|| Xoshiro256PlusPlus::seed_from_u64(42),
|mut rand| io::copy(&mut rand.read_adapter().take(100), &mut io::sink()),
);
});
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
Thanks! |
No description provided.