From 80eb616bd3e502d4fcb0541a92ec75f2921294d9 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 3 Oct 2014 21:20:04 +0100 Subject: [PATCH] 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. --- src/libcollections/string.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index d6adbd302645..2cc225f50bc3 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -269,7 +269,7 @@ impl String { /// ``` #[unstable = "error value in return may change"] pub fn from_utf16(v: &[u16]) -> Option { - let mut s = String::with_capacity(v.len() / 2); + let mut s = String::with_capacity(v.len()); for c in str::utf16_items(v) { match c { str::ScalarValue(c) => s.push(c),