From 6584ae54917a74d8bf83c1047f273d5210d2a015 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 13 Mar 2015 09:56:18 +0100 Subject: slice::from_raw_parts is preferred over transmuting a fresh raw::Slice --- src/libstd/sys/common/wtf8.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/libstd/sys') 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 -- cgit 1.4.1-3-g733a5