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

Add encode_to API #66

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add encode_to API #66

wants to merge 2 commits into from

Conversation

cgwalters
Copy link

In https://github.com/ostreedev/ostree-rs-ext/ we are performing
hex encoding in loops and recursively, and it could be helpful
for performance to support re-using a buffer instead of allocating
a new String on the heap.

Currently we are using encode_to_slice, but then we need to
use e.g. std::str::from_utf8 which unnecessarily performs UTF-8
validation and is also hence fallible even though it doesn't need to be.

@cgwalters
Copy link
Author

Another alternative is to just make BytesToHexChars public.

src/lib.rs Outdated Show resolved Hide resolved
@cgwalters cgwalters force-pushed the encode-to branch 2 times, most recently from d6d0122 to 8df0405 Compare December 17, 2021 19:08
@cgwalters
Copy link
Author

OK this is also much cleaner using String::extend and even better will honor the size hint.

To fix CI for git main/master.
In https://github.com/ostreedev/ostree-rs-ext/ we are performing
hex encoding in loops and recursively, and it could be helpful
for performance to support re-using a buffer instead of allocating
a new `String` on the heap.

Currently we are using `encode_to_slice`, but then we need to
use e.g. `std::str::from_utf8` which unnecessarily performs UTF-8
validation and is also hence fallible even though it doesn't need to be.
@cgwalters
Copy link
Author

I rolled in #67 here.

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.

1 participant