-
Notifications
You must be signed in to change notification settings - Fork 253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fixed_result_into
to prevent copy
#86
Comments
It seems like with const generics on the horizon there should (possibly) be a way to do this in terms of https://internals.rust-lang.org/t/collecting-iterators-into-arrays/10330 |
I was thinking about doing the following re-design in the next pub trait FixedOutput {
type OutputSize: ArrayLength<u8>;
/// Private method not intended to be used directly
fn _fixed_result_core(&mut self, out: &mut GenericArray<u8, Self::OutputSize>, reset: bool);
#[inline]
fn fixed_result(self) -> GenericArray<u8, Self::OutputSize> {
let mut buf = Default::default();
self._fixed_result_core(&mut buf, false);
buf
}
#[inline]
fn fixed_result_reset(&mut self) -> GenericArray<u8, Self::OutputSize> { .. }
fn fixed_result_into(self, out: &mut GenericArray<u8, Self::OutputSize>) { .. }
fn fixed_result_into_reset(&mut self, out: &mut GenericArray<u8, Self::OutputSize>) { .. }
} I think |
tarcieri
added a commit
to RustCrypto/traits
that referenced
this issue
Jun 9, 2020
Closes RustCrypto/hashes#86 Replaces the `Reset` trait with a set of `_reset` methods on all of the various traits, and uses these as the default impl for the methods which consume hashers. Also adds a set of methods to `FixedOutput` (`finalize_fixed_into*`) which eliminate copies by accepting an existing buffer as an argument.
tarcieri
added a commit
to RustCrypto/traits
that referenced
this issue
Jun 9, 2020
Closes RustCrypto/hashes#86 Replaces the `Reset` trait with a set of `_reset` methods on all of the various traits, and uses these as the default impl for the methods which consume hashers. Also adds a set of methods to `FixedOutput` (`finalize_fixed_into*`) which eliminate copies by accepting an existing buffer as an argument.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rust does not (yet) implement named return value optimisation, so
fixed_result
forces a copy.How would you feel about adding a
function to the
FixedOutput
trait so that the copy can be avoided. I'm happy to create a PR.(Background: I'm implementing the hash-based signature XMSSMT in rust, where lots of hashes are computed on on very short inputs. These copies have a significant overhead.)
The text was updated successfully, but these errors were encountered: