-
Notifications
You must be signed in to change notification settings - Fork 41
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
Convert from Hash to/from PinnedSizedBytes safely #292
Comments
There seems to be an odd distinction between |
@kozross They are quite different underneath. |
I understand they are implemented quite differently: why can't we unify their representations? I don't really see why they need to be separate in the first place. |
It is right in the name: one is pinned another one is not 😄 |
Yeah, I guess that's true, but at the same time, I feel that making both things use |
I'm also wondering if there'd ever come a time when we might want to generate hashes via the FFI: we don't need this currently, but we might one day. |
I see what you are trying to say. Putting pinnedness aside, the whole point why data Hash32 = Hash32 {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64 will use 30% less memory than newtype Hash32 = Hash32 (PinnedSizedBytes 32) We store a lot of hashes in memory and it makes a difference.
We are already producing hashes over ffi with libsodium, we just immediately convert them to |
Interesting - I've learned something new today. In that case, the difference in representation definitely makes sense. It would still be nice to have a safe conversion though. |
That's exactly what this ticket is about 😉 |
There is a way to implement a total function that does this conversion because we now statically both of their sizes. This came up in #289
The text was updated successfully, but these errors were encountered: