Skip to content

Commit 80eb616

Browse files
committed
Fix preallocation amount in String::from_utf16
`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.
1 parent 9a2286d commit 80eb616

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libcollections/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl String {
269269
/// ```
270270
#[unstable = "error value in return may change"]
271271
pub fn from_utf16(v: &[u16]) -> Option<String> {
272-
let mut s = String::with_capacity(v.len() / 2);
272+
let mut s = String::with_capacity(v.len());
273273
for c in str::utf16_items(v) {
274274
match c {
275275
str::ScalarValue(c) => s.push(c),

0 commit comments

Comments
 (0)