Skip to content

Commit 0927ef4

Browse files
brendanzabalexcrichton
authored andcommitted
---
yaml --- r: 121303 b: refs/heads/dist-snap c: b84d17d h: refs/heads/master i: 121301: 7c89b2c 121299: 952d611 121295: b59622a v: v3
1 parent e035b4c commit 0927ef4

File tree

6 files changed

+45
-57
lines changed

6 files changed

+45
-57
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 1813e5aa1a03b0596b8de7abd1af31edf5d6098f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 87c529c43a41e0c04a468cd2b301013df629b040
9+
refs/heads/dist-snap: b84d17d4d77b04e1b7784d95e0c3cb2dca16f344
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcollections/hash/mod.rs

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -98,46 +98,31 @@ pub trait Writer {
9898

9999
//////////////////////////////////////////////////////////////////////////////
100100

101-
fn id<T>(t: T) -> T { t }
102-
103-
macro_rules! impl_hash(
104-
( $($ty:ident, $uty:ident, $f:path;)* ) => (
105-
$(
106-
impl<S: Writer> Hash<S> for $ty {
107-
#[inline]
108-
fn hash(&self, state: &mut S) {
109-
let a: [u8, ..::core::$ty::BYTES] = unsafe {
110-
mem::transmute($f(*self as $uty) as $ty)
111-
};
112-
state.write(a.as_slice())
113-
}
101+
macro_rules! impl_hash {
102+
($ty:ident, $uty:ident) => {
103+
impl<S: Writer> Hash<S> for $ty {
104+
#[inline]
105+
fn hash(&self, state: &mut S) {
106+
use core::mem::ByteOrder;
107+
let a: [u8, ..::core::$ty::BYTES] = unsafe {
108+
mem::transmute((*self as $uty).to_little_endian() as $ty)
109+
};
110+
state.write(a.as_slice())
114111
}
115-
)*
116-
)
117-
)
118-
119-
impl_hash!(
120-
u8, u8, id;
121-
u16, u16, mem::to_le16;
122-
u32, u32, mem::to_le32;
123-
u64, u64, mem::to_le64;
124-
i8, u8, id;
125-
i16, u16, mem::to_le16;
126-
i32, u32, mem::to_le32;
127-
i64, u64, mem::to_le64;
128-
)
129-
130-
#[cfg(target_word_size = "32")]
131-
impl_hash!(
132-
uint, u32, mem::to_le32;
133-
int, u32, mem::to_le32;
134-
)
112+
}
113+
}
114+
}
135115

136-
#[cfg(target_word_size = "64")]
137-
impl_hash!(
138-
uint, u64, mem::to_le64;
139-
int, u64, mem::to_le64;
140-
)
116+
impl_hash!(u8, u8)
117+
impl_hash!(u16, u16)
118+
impl_hash!(u32, u32)
119+
impl_hash!(u64, u64)
120+
impl_hash!(uint, uint)
121+
impl_hash!(i8, u8)
122+
impl_hash!(i16, u16)
123+
impl_hash!(i32, u32)
124+
impl_hash!(i64, u64)
125+
impl_hash!(int, uint)
141126

142127
impl<S: Writer> Hash<S> for bool {
143128
#[inline]

branches/dist-snap/src/libnative/io/net.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use alloc::arc::Arc;
1212
use libc;
1313
use std::mem;
14+
use std::mem::ByteOrder;
1415
use std::rt::mutex;
1516
use std::rt::rtio;
1617
use std::rt::rtio::{IoResult, IoError};
@@ -27,10 +28,10 @@ use super::util;
2728
#[cfg(unix)] pub type sock_t = super::file::fd_t;
2829

2930
pub fn htons(u: u16) -> u16 {
30-
mem::to_be16(u)
31+
u.to_big_endian()
3132
}
3233
pub fn ntohs(u: u16) -> u16 {
33-
mem::from_be16(u)
34+
ByteOrder::from_big_endian(u)
3435
}
3536

3637
enum InAddr {
@@ -46,7 +47,7 @@ fn ip_to_inaddr(ip: rtio::IpAddr) -> InAddr {
4647
(c as u32 << 8) |
4748
(d as u32 << 0);
4849
InAddr(libc::in_addr {
49-
s_addr: mem::from_be32(ip)
50+
s_addr: ByteOrder::from_big_endian(ip)
5051
})
5152
}
5253
rtio::Ipv6Addr(a, b, c, d, e, f, g, h) => {
@@ -180,7 +181,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
180181
let storage: &libc::sockaddr_in = unsafe {
181182
mem::transmute(storage)
182183
};
183-
let ip = mem::to_be32(storage.sin_addr.s_addr as u32);
184+
let ip = (storage.sin_addr.s_addr as u32).to_big_endian();
184185
let a = (ip >> 24) as u8;
185186
let b = (ip >> 16) as u8;
186187
let c = (ip >> 8) as u8;

branches/dist-snap/src/librustuv/net.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use libc::{size_t, ssize_t, c_int, c_void, c_uint};
1212
use libc;
1313
use std::mem;
14+
use std::mem::ByteOrder;
1415
use std::ptr;
1516
use std::rt::rtio;
1617
use std::rt::rtio::IoError;
@@ -30,8 +31,8 @@ use uvll;
3031
/// Generic functions related to dealing with sockaddr things
3132
////////////////////////////////////////////////////////////////////////////////
3233

33-
pub fn htons(u: u16) -> u16 { mem::to_be16(u) }
34-
pub fn ntohs(u: u16) -> u16 { mem::from_be16(u) }
34+
pub fn htons(u: u16) -> u16 { u.to_big_endian() }
35+
pub fn ntohs(u: u16) -> u16 { ByteOrder::from_big_endian(u) }
3536

3637
pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
3738
len: uint) -> rtio::SocketAddr {
@@ -41,7 +42,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
4142
let storage: &libc::sockaddr_in = unsafe {
4243
mem::transmute(storage)
4344
};
44-
let ip = mem::to_be32(storage.sin_addr.s_addr as u32);
45+
let ip = (storage.sin_addr.s_addr as u32).to_big_endian();
4546
let a = (ip >> 24) as u8;
4647
let b = (ip >> 16) as u8;
4748
let c = (ip >> 8) as u8;
@@ -89,7 +90,8 @@ fn addr_to_sockaddr(addr: rtio::SocketAddr) -> (libc::sockaddr_storage, uint) {
8990
(*storage).sin_family = libc::AF_INET as libc::sa_family_t;
9091
(*storage).sin_port = htons(addr.port);
9192
(*storage).sin_addr = libc::in_addr {
92-
s_addr: mem::from_be32(ip)
93+
s_addr: ByteOrder::from_big_endian(ip),
94+
9395
};
9496
mem::size_of::<libc::sockaddr_in>()
9597
}

branches/dist-snap/src/libserialize/ebml.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub mod reader {
154154
}
155155

156156
pub fn vuint_at(data: &[u8], start: uint) -> DecodeResult<Res> {
157-
use std::mem::from_be32;
157+
use std::mem::ByteOrder;
158158

159159
if data.len() - start < 4 {
160160
return vuint_at_slow(data, start);
@@ -185,7 +185,7 @@ pub mod reader {
185185

186186
unsafe {
187187
let ptr = data.as_ptr().offset(start as int) as *u32;
188-
let val = from_be32(*ptr);
188+
let val = ByteOrder::from_big_endian(*ptr);
189189

190190
let i = (val >> 28u) as uint;
191191
let (shift, mask) = SHIFT_MASK_TABLE[i];

branches/dist-snap/src/libuuid/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl Uuid {
209209
/// * `d3` A 16-bit word
210210
/// * `d4` Array of 8 octets
211211
pub fn from_fields(d1: u32, d2: u16, d3: u16, d4: &[u8]) -> Uuid {
212-
use std::mem::{to_be16, to_be32};
212+
use std::mem::ByteOrder;
213213

214214
// First construct a temporary field-based struct
215215
let mut fields = UuidFields {
@@ -219,9 +219,9 @@ impl Uuid {
219219
data4: [0, ..8]
220220
};
221221

222-
fields.data1 = to_be32(d1);
223-
fields.data2 = to_be16(d2);
224-
fields.data3 = to_be16(d3);
222+
fields.data1 = d1.to_big_endian();
223+
fields.data2 = d2.to_big_endian();
224+
fields.data3 = d3.to_big_endian();
225225
slice::bytes::copy_memory(fields.data4, d4);
226226

227227
unsafe {
@@ -335,16 +335,16 @@ impl Uuid {
335335
///
336336
/// Example: `550e8400-e29b-41d4-a716-446655440000`
337337
pub fn to_hyphenated_str(&self) -> String {
338-
use std::mem::{to_be16, to_be32};
338+
use std::mem::ByteOrder;
339339
// Convert to field-based struct as it matches groups in output.
340340
// Ensure fields are in network byte order, as per RFC.
341341
let mut uf: UuidFields;
342342
unsafe {
343343
uf = transmute_copy(&self.bytes);
344344
}
345-
uf.data1 = to_be32(uf.data1);
346-
uf.data2 = to_be16(uf.data2);
347-
uf.data3 = to_be16(uf.data3);
345+
uf.data1 = uf.data1.to_big_endian();
346+
uf.data2 = uf.data2.to_big_endian();
347+
uf.data3 = uf.data3.to_big_endian();
348348
let s = format!("{:08x}-{:04x}-{:04x}-{:02x}{:02x}-\
349349
{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
350350
uf.data1,

0 commit comments

Comments
 (0)