Skip to content

Commit 9e8d5aa

Browse files
committed
arena,std,serialize: remove some unnecessary transmutes.
`as`-able transmutes, duplication and manual slice decomposition are silly.
1 parent 4cc723d commit 9e8d5aa

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

src/libarena/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,12 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
167167
// is necessary in order to properly do cleanup if a failure occurs
168168
// during an initializer.
169169
#[inline]
170-
unsafe fn bitpack_tydesc_ptr(p: *TyDesc, is_done: bool) -> uint {
171-
let p_bits: uint = transmute(p);
172-
p_bits | (is_done as uint)
170+
fn bitpack_tydesc_ptr(p: *TyDesc, is_done: bool) -> uint {
171+
p as uint | (is_done as uint)
173172
}
174173
#[inline]
175-
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) {
176-
(transmute(p & !1), p & 1 == 1)
174+
fn un_bitpack_tydesc_ptr(p: uint) -> (*TyDesc, bool) {
175+
((p & !1) as *TyDesc, p & 1 == 1)
177176
}
178177

179178
impl Arena {

src/libserialize/ebml.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ pub mod reader {
161161
];
162162

163163
unsafe {
164-
let (ptr, _): (*u8, uint) = transmute(data);
165-
let ptr = ptr.offset(start as int);
166-
let ptr: *i32 = transmute(ptr);
164+
let ptr = data.as_ptr().offset(start as int) as *i32;
167165
let val = from_be32(*ptr) as u32;
168166

169167
let i = (val >> 28u) as uint;

src/libstd/num/f32.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,8 @@ impl Float for f32 {
351351
static EXP_MASK: u32 = 0x7f800000;
352352
static MAN_MASK: u32 = 0x007fffff;
353353

354-
match (
355-
unsafe { ::cast::transmute::<f32,u32>(*self) } & MAN_MASK,
356-
unsafe { ::cast::transmute::<f32,u32>(*self) } & EXP_MASK,
357-
) {
354+
let bits: u32 = unsafe {::cast::transmute(*self)};
355+
match (bits & MAN_MASK, bits & EXP_MASK) {
358356
(0, 0) => FPZero,
359357
(_, 0) => FPSubnormal,
360358
(0, EXP_MASK) => FPInfinite,

src/libstd/num/f64.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,8 @@ impl Float for f64 {
353353
static EXP_MASK: u64 = 0x7ff0000000000000;
354354
static MAN_MASK: u64 = 0x000fffffffffffff;
355355

356-
match (
357-
unsafe { ::cast::transmute::<f64,u64>(*self) } & MAN_MASK,
358-
unsafe { ::cast::transmute::<f64,u64>(*self) } & EXP_MASK,
359-
) {
356+
let bits: u64 = unsafe {::cast::transmute(*self)};
357+
match (bits & MAN_MASK, bits & EXP_MASK) {
360358
(0, 0) => FPZero,
361359
(_, 0) => FPSubnormal,
362360
(0, EXP_MASK) => FPInfinite,

0 commit comments

Comments
 (0)