diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2014-10-03 21:20:04 +0100 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2014-10-03 21:20:04 +0100 |
| commit | 80eb616bd3e502d4fcb0541a92ec75f2921294d9 (patch) | |
| tree | 6e9fd348c1a05a0d2e321d1a426f3ed648af3a8d | |
| parent | 9a2286d3a13c4a97340c99c86c718654f6cb2ed6 (diff) | |
| download | rust-80eb616bd3e502d4fcb0541a92ec75f2921294d9.tar.gz rust-80eb616bd3e502d4fcb0541a92ec75f2921294d9.zip | |
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.
| -rw-r--r-- | src/libcollections/string.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index d6adbd30264..2cc225f50bc 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<String> { - 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), |
