Skip to content

Fix preallocation amount in String::from_utf16 #17752

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

Merged
merged 1 commit into from
Oct 4, 2014

Conversation

SimonSapin
Copy link
Contributor

v.len() counts code units, not UTF-16 bytes. The lower bound is one UTF-8 byte per code unit, not per two code units.

I believe this is correct, but it’s late. Someone please double check.

`v.len()` counts code units, not UTF-16 bytes. The lower bound is one UTF-8 byte per code unit, not per two code units.
@thestinger
Copy link
Contributor

The lower bound is 1 byte per code unit since it could all be code units representing code points that UTF-8 covers with 1 byte.

@SimonSapin
Copy link
Contributor Author

Yeah, that’s what I thought. with_capacity(v.len() / 2) means one byte per two code units, which doesn’t match anything.

bors added a commit that referenced this pull request Oct 4, 2014
`v.len()` counts code units, not UTF-16 bytes. The lower bound is one UTF-8 byte per code unit, not per two code units.

I believe this is correct, but it’s late. Someone please double check.
@bors bors closed this Oct 4, 2014
@bors bors merged commit 80eb616 into rust-lang:master Oct 4, 2014
@SimonSapin SimonSapin deleted the patch-6 branch December 5, 2014 17:34
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.

3 participants