Skip to content

Commit

Permalink
libextra: Use from_be32 instead of bswap32 in vuint_at()
Browse files Browse the repository at this point in the history
Also use the fast version of vuint_at() on all architectures since it now
works on both big and little endian architectures.
  • Loading branch information
c-a committed Jan 1, 2014
1 parent 19d8ab8 commit 1c3c010
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/libextra/ebml.rs
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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() }
}
Expand Down

5 comments on commit 1c3c010

@bors
Copy link
Contributor

@bors bors commented on 1c3c010 Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at c-a@1c3c010

@bors
Copy link
Contributor

@bors bors commented on 1c3c010 Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging c-a/rust/byteswap_from = 1c3c010 into auto

@bors
Copy link
Contributor

@bors bors commented on 1c3c010 Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c-a/rust/byteswap_from = 1c3c010 merged ok, testing candidate = ee634e3

@bors
Copy link
Contributor

@bors bors commented on 1c3c010 Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 1c3c010 Jan 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = ee634e3

Please sign in to comment.