about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorOliver Schneider <git1984941651981@oli-obk.de>2015-03-13 09:56:18 +0100
committerOliver Schneider <git1984941651981@oli-obk.de>2015-03-13 09:56:18 +0100
commit6584ae54917a74d8bf83c1047f273d5210d2a015 (patch)
tree95ae30713d804f21d5fc261df4304fe8d867edc5 /src/libstd/sys
parent8715a65496b557798a9ff346194991aea3581f4d (diff)
downloadrust-6584ae54917a74d8bf83c1047f273d5210d2a015.tar.gz
rust-6584ae54917a74d8bf83c1047f273d5210d2a015.zip
slice::from_raw_parts is preferred over transmuting a fresh raw::Slice
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/common/wtf8.rs18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs
index 7a02df23b19..991fe46eb29 100644
--- a/src/libstd/sys/common/wtf8.rs
+++ b/src/libstd/sys/common/wtf8.rs
@@ -25,7 +25,6 @@ use core::prelude::*;
 
 use core::char::{encode_utf8_raw, encode_utf16_raw};
 use core::str::{char_range_at_raw, next_code_point};
-use core::raw::Slice as RawSlice;
 
 use ascii::*;
 use borrow::Cow;
@@ -210,10 +209,10 @@ impl Wtf8Buf {
         unsafe {
             // Attempt to not use an intermediate buffer by just pushing bytes
             // directly onto this string.
-            let slice = RawSlice {
-                data: self.bytes.as_ptr().offset(cur_len as int),
-                len: 4,
-            };
+            let slice = slice::from_raw_parts_mut(
+                self.bytes.as_mut_ptr().offset(cur_len as int),
+                4
+            );
             let used = encode_utf8_raw(code_point.value, mem::transmute(slice))
                 .unwrap_or(0);
             self.bytes.set_len(cur_len + used);
@@ -721,10 +720,11 @@ pub fn is_code_point_boundary(slice: &Wtf8, index: uint) -> bool {
 /// Copied from core::str::raw::slice_unchecked
 #[inline]
 pub unsafe fn slice_unchecked(s: &Wtf8, begin: uint, end: uint) -> &Wtf8 {
-    mem::transmute(RawSlice {
-        data: s.bytes.as_ptr().offset(begin as int),
-        len: end - begin,
-    })
+    // memory layout of an &[u8] and &Wtf8 are the same
+    mem::transmute(slice::from_raw_parts(
+        s.bytes.as_ptr().offset(begin as int),
+        end - begin
+    ))
 }
 
 /// Copied from core::str::raw::slice_error_fail