diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-14 20:04:14 +1000 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-15 19:45:00 -0700 |
| commit | 54ec04f1c12c7fb4dbe5f01fdeb73d1079fef53d (patch) | |
| tree | efe91e930ac4527e3057fe65571df112ef5b8607 /src/libstd/io | |
| parent | 93dc55518840ee3cbd570c0d85aa7a445752af8b (diff) | |
| download | rust-54ec04f1c12c7fb4dbe5f01fdeb73d1079fef53d.tar.gz rust-54ec04f1c12c7fb4dbe5f01fdeb73d1079fef53d.zip | |
Use the unsigned integer types for bitwise intrinsics.
Exposing ctpop, ctlz, cttz and bswap as taking signed i8/i16/... is just exposing the internal LLVM names pointlessly (LLVM doesn't have "signed integers" or "unsigned integers", it just has sized integer types with (un)signed *operations*). These operations are semantically working with raw bytes, which the unsigned types model better.
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/extensions.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index b2202a13057..d8022b1e26c 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -83,9 +83,9 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { assert!(size <= 8u); match size { 1u => f(&[n as u8]), - 2u => f(unsafe { transmute::<i16, [u8, ..2]>(to_le16(n as i16)) }), - 4u => f(unsafe { transmute::<i32, [u8, ..4]>(to_le32(n as i32)) }), - 8u => f(unsafe { transmute::<i64, [u8, ..8]>(to_le64(n as i64)) }), + 2u => f(unsafe { transmute::<_, [u8, ..2]>(to_le16(n as u16)) }), + 4u => f(unsafe { transmute::<_, [u8, ..4]>(to_le32(n as u32)) }), + 8u => f(unsafe { transmute::<_, [u8, ..8]>(to_le64(n)) }), _ => { let mut bytes = vec!(); @@ -123,9 +123,9 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { assert!(size <= 8u); match size { 1u => f(&[n as u8]), - 2u => f(unsafe { transmute::<i16, [u8, ..2]>(to_be16(n as i16)) }), - 4u => f(unsafe { transmute::<i32, [u8, ..4]>(to_be32(n as i32)) }), - 8u => f(unsafe { transmute::<i64, [u8, ..8]>(to_be64(n as i64)) }), + 2u => f(unsafe { transmute::<_, [u8, ..2]>(to_be16(n as u16)) }), + 4u => f(unsafe { transmute::<_, [u8, ..4]>(to_be32(n as u32)) }), + 8u => f(unsafe { transmute::<_, [u8, ..8]>(to_be64(n)) }), _ => { let mut bytes = vec!(); let mut i = size; @@ -166,7 +166,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { let ptr = data.as_ptr().offset(start as int); let out = buf.as_mut_ptr(); copy_nonoverlapping_memory(out.offset((8 - size) as int), ptr, size); - from_be64(*(out as *i64)) as u64 + from_be64(*(out as *u64)) } } |
