mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-23 12:23:22 +00:00
libextra: Use from_be32 instead of bswap32 in vuint_at()
Also use the fast version of vuint_at() on all architectures since it now works on both big and little endian architectures.
This commit is contained in:
parent
19d8ab8d5a
commit
1c3c0103c4
@ -122,11 +122,9 @@ pub mod reader {
|
||||
fail!("vint too big");
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub fn vuint_at(data: &[u8], start: uint) -> Res {
|
||||
use std::ptr::offset;
|
||||
use std::unstable::intrinsics::bswap32;
|
||||
use std::unstable::intrinsics::from_be32;
|
||||
|
||||
if data.len() - start < 4 {
|
||||
return vuint_at_slow(data, start);
|
||||
@ -136,7 +134,7 @@ pub mod reader {
|
||||
let (ptr, _): (*u8, uint) = transmute(data);
|
||||
let ptr = offset(ptr, start as int);
|
||||
let ptr: *i32 = transmute(ptr);
|
||||
let val = bswap32(*ptr);
|
||||
let val = from_be32(*ptr);
|
||||
let val: u32 = transmute(val);
|
||||
if (val & 0x80000000) != 0 {
|
||||
Res {
|
||||
@ -162,11 +160,6 @@ pub mod reader {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "x86"), not(target_arch = "x86_64"))]
|
||||
pub fn vuint_at(data: &[u8], start: uint) -> Res {
|
||||
vuint_at_slow(data, start)
|
||||
}
|
||||
|
||||
pub fn Doc<'a>(data: &'a [u8]) -> Doc<'a> {
|
||||
Doc { data: data, start: 0u, end: data.len() }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user