Skip to content

Fix preallocation amount in String::from_utf16 - #17752

Merged
bors merged 1 commit into
rust-lang:masterfrom
SimonSapin:patch-6
Oct 4, 2014
Merged

bors merged 1 commit into
rust-lang:masterfrom
SimonSapin:patch-6

Conversation

@SimonSapin

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 24, 2026
…g#17752)

Implements part of rust-lang/rust-clippy#17485

Unleaking a leaked `Box` pointer isn't well defined, so we shouldn't be
suggesting to change `into_raw` into `leak`. This needs to be backported
to beta and ideally would be synced before a new beta is branched off.

r? flip1995

changelog: [`nonnull_unchecked_on_box_ptr`]: Don't suggest `Box::leak`
Kobzol pushed a commit to Kobzol/rust that referenced this pull request Sep 29, 2026
…g#17752)

Implements part of rust-lang/rust-clippy#17485

Unleaking a leaked `Box` pointer isn't well defined, so we shouldn't be
suggesting to change `into_raw` into `leak`. This needs to be backported
to beta and ideally would be synced before a new beta is branched off.

r? flip1995

changelog: [`nonnull_unchecked_on_box_ptr`]: Don't suggest `Box::leak`
flip1995 pushed a commit to flip1995/rust that referenced this pull request Oct 1, 2026
…g#17752)

Implements part of rust-lang/rust-clippy#17485

Unleaking a leaked `Box` pointer isn't well defined, so we shouldn't be
suggesting to change `into_raw` into `leak`. This needs to be backported
to beta and ideally would be synced before a new beta is branched off.

r? flip1995

changelog: [`nonnull_unchecked_on_box_ptr`]: Don't suggest `Box::leak`
JonathanBrouwer pushed a commit to JonathanBrouwer/rust that referenced this pull request Nov 5, 2026
…g#17752)

Implements part of rust-lang/rust-clippy#17485

Unleaking a leaked `Box` pointer isn't well defined, so we shouldn't be
suggesting to change `into_raw` into `leak`. This needs to be backported
to beta and ideally would be synced before a new beta is branched off.

r? flip1995

changelog: [`nonnull_unchecked_on_box_ptr`]: Don't suggest `Box::leak`
JonathanBrouwer pushed a commit to JonathanBrouwer/rust that referenced this pull request Nov 5, 2026
…g#17752)

Implements part of rust-lang/rust-clippy#17485

Unleaking a leaked `Box` pointer isn't well defined, so we shouldn't be
suggesting to change `into_raw` into `leak`. This needs to be backported
to beta and ideally would be synced before a new beta is branched off.

r? flip1995

changelog: [`nonnull_unchecked_on_box_ptr`]: Don't suggest `Box::leak`
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