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

Avoid allocations on os_str_{from,to}_bytes on Windows #13

Closed
wants to merge 1 commit into from

Conversation

glandium
Copy link

When dealing with valid utf-8, which is expected to be the most common case, we can just use the data as is. The downside is having to go over the string twice if it's not valid utf-8.

When dealing with valid utf-8, which is expected to be the most common case,
we can just use the data as is. The downside is having to go over the string
twice if it's not valid utf-8.
@dylni
Copy link
Owner

dylni commented Oct 29, 2022

Thanks for the PR! I've considered this, but I don't think it's the right approach. This would add an unavoidable performance penalty to every conversion with non-UTF-8 bytes, rather than letting the user decide if UTF-8 should be parsed first.

However, it should be possible to do better. For os_str_from_bytes, this crate can easily tell if the bytes are valid UTF-8 while encoding, so I have an idea to avoid some work. For os_str_to_bytes, I would prefer to wait until this ACP is accepted to avoid the penalty.

Therefore, I am going to close this PR, as I do not plan to take this approach. Let me know if you have any additional input, and thank you for the suggestion!

@dylni dylni closed this Oct 29, 2022
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