Skip to content
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

Raw fst .as_bytes() #77

Merged
merged 1 commit into from
Dec 15, 2018
Merged

Raw fst .as_bytes() #77

merged 1 commit into from
Dec 15, 2018

Conversation

vorner
Copy link
Contributor

@vorner vorner commented Dec 15, 2018

Similar to .to_vec(), but without making copies.

Motivation

  • Currently, I'm keeping a map in memory and exchange it from time to time. Later on I'd like to store it to a cache (but not at the time when I'm constructing it) and currently I have to use the to_vec and then write_all ‒ which is wasteful, because it creates a copy of the whole thing in memory.
  • For some metrics I'd like to know the size of the image (not .len() ‒ that one is number of keys). Calling to_vec for that is obviously too wasteful.

If this change is OK, would it be fine to have a release with it?

Thank you

Similar to .to_vec(), but without making copies.
@BurntSushi
Copy link
Owner

BurntSushi commented Dec 15, 2018

@vorner Thanks for the PR! I'm not in principle opposed to this change. IIRC, the reason why it didn't already exist is because the &[u8] tends to be a memory map, or at the very least, could be a memory map. In that circumstance, getting access to the raw slice without needing to type unsafe would be bad. With that said, in the last release, I made it so constructing an FST from a memory map required typing unsafe. See here and here and here. There is even a safe method called as_bytes on the MmapReadOnly type. So to that end, I think the lack of this method is just an oversight and this should be OK!

@BurntSushi BurntSushi merged commit 2c100f6 into BurntSushi:master Dec 15, 2018
@BurntSushi
Copy link
Owner

This PR is now on crates.io in fst 0.3.3.

@vorner
Copy link
Contributor Author

vorner commented Dec 15, 2018

Thank you :-)

What I was thinking ‒ accessing the slice should not be more dangerous than doing .search or something like that on the fst anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants