about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authortormol <t.b.moltu@lyse.net>2016-09-08 13:54:39 +0200
committertormol <t.b.moltu@lyse.net>2016-09-28 09:03:30 +0200
commit13a2dd96fe824cc5d61e94ed380db0114efdd014 (patch)
tree808a2f28e42625a2e5bc4a88abf2d46c34727b32 /src/libstd/sys
parenta059cb2f3344c0a9efae17dde3d0e16a55ce93db (diff)
downloadrust-13a2dd96fe824cc5d61e94ed380db0114efdd014.tar.gz
rust-13a2dd96fe824cc5d61e94ed380db0114efdd014.zip
[breaking-change] std: change `encode_utf{8,16}()` to take a buffer and return a slice
They panic if the buffer is too small.
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/common/wtf8.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs
index 8d357aa78c9..0a94ff1e958 100644
--- a/src/libstd/sys/common/wtf8.rs
+++ b/src/libstd/sys/common/wtf8.rs
@@ -206,10 +206,12 @@ impl Wtf8Buf {
     /// Copied from String::push
     /// This does **not** include the WTF-8 concatenation check.
     fn push_code_point_unchecked(&mut self, code_point: CodePoint) {
-        let bytes = unsafe {
-            char::from_u32_unchecked(code_point.value).encode_utf8()
+        let c = unsafe {
+            char::from_u32_unchecked(code_point.value)
         };
-        self.bytes.extend_from_slice(bytes.as_slice());
+        let mut bytes = [0; 4];
+        let bytes = c.encode_utf8(&mut bytes).as_bytes();
+        self.bytes.extend_from_slice(bytes)
     }
 
     #[inline]
@@ -738,15 +740,16 @@ impl<'a> Iterator for EncodeWide<'a> {
             return Some(tmp);
         }
 
+        let mut buf = [0; 2];
         self.code_points.next().map(|code_point| {
-            let n = unsafe {
-                char::from_u32_unchecked(code_point.value).encode_utf16()
+            let c = unsafe {
+                char::from_u32_unchecked(code_point.value)
             };
-            let n = n.as_slice();
-            if n.len() == 2 {
-                self.extra = n[1];
+            let n = c.encode_utf16(&mut buf).len();
+            if n == 2 {
+                self.extra = buf[1];
             }
-            n[0]
+            buf[0]
         })
     }