Skip to content

Commit ceb34cd

Browse files
brendanzabalexcrichton
authored andcommitted
---
yaml --- r: 121305 b: refs/heads/dist-snap c: ff9f92c h: refs/heads/master i: 121303: 0927ef4 v: v3
1 parent 0e278dc commit ceb34cd

File tree

15 files changed

+326
-365
lines changed

15 files changed

+326
-365
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: 4c0f8f49f6fe860efa268efa2f4fa0b5f00a4b07
9+
refs/heads/dist-snap: ff9f92ce5224f5e27b8dc39ffc02eb9481f7cff1
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcollections/enum_set.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
1616
use core::prelude::*;
1717

18-
use core::num::Bitwise;
19-
2018
#[deriving(Clone, PartialEq, Eq, Hash, Show)]
2119
/// A specialized Set implementation to use enum types.
2220
pub struct EnumSet<E> {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ macro_rules! impl_hash {
103103
impl<S: Writer> Hash<S> for $ty {
104104
#[inline]
105105
fn hash(&self, state: &mut S) {
106-
use core::mem::ByteOrder;
107106
let a: [u8, ..::core::$ty::BYTES] = unsafe {
108107
mem::transmute((*self as $uty).to_little_endian() as $ty)
109108
};

branches/dist-snap/src/libcore/mem.rs

Lines changed: 8 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
//! This module contains functions for querying the size and alignment of
1414
//! types, initializing and manipulating memory.
1515
16-
use clone::Clone;
17-
use ptr;
1816
use intrinsics;
19-
use intrinsics::{bswap16, bswap32, bswap64};
17+
use num::Int;
18+
use ptr;
2019

2120
pub use intrinsics::transmute;
2221

@@ -170,155 +169,6 @@ pub unsafe fn move_val_init<T>(dst: &mut T, src: T) {
170169
ptr::write(dst, src)
171170
}
172171

173-
/// A type that can have its bytes re-ordered.
174-
pub trait ByteOrder: Clone {
175-
/// Reverses the byte order of the value.
176-
///
177-
/// # Example
178-
///
179-
/// ```rust
180-
/// use std::mem::ByteOrder;
181-
///
182-
/// let n = 0x0123456789ABCDEFu64;
183-
/// let m = 0xEFCDAB8967452301u64;
184-
///
185-
/// assert_eq!(n.swap_bytes(), m);
186-
/// ```
187-
fn swap_bytes(&self) -> Self;
188-
189-
/// Convert a value from big endian to the target's endianness.
190-
///
191-
/// On big endian this is a no-op. On little endian the bytes are swapped.
192-
///
193-
/// # Example
194-
///
195-
/// ```rust
196-
/// use std::mem::ByteOrder;
197-
///
198-
/// let n = 0x0123456789ABCDEFu64;
199-
///
200-
/// if cfg!(target_endian = "big") {
201-
/// assert_eq!(ByteOrder::from_big_endian(n), n)
202-
/// } else {
203-
/// assert_eq!(ByteOrder::from_big_endian(n), n.swap_bytes())
204-
/// }
205-
/// ```
206-
#[inline]
207-
fn from_big_endian(x: Self) -> Self {
208-
if cfg!(target_endian = "big") { x } else { x.swap_bytes() }
209-
}
210-
211-
/// Convert a value from little endian to the target's endianness.
212-
///
213-
/// On little endian this is a no-op. On big endian the bytes are swapped.
214-
///
215-
/// # Example
216-
///
217-
/// ```rust
218-
/// use std::mem::ByteOrder;
219-
///
220-
/// let n = 0x0123456789ABCDEFu64;
221-
///
222-
/// if cfg!(target_endian = "little") {
223-
/// assert_eq!(ByteOrder::from_little_endian(n), n)
224-
/// } else {
225-
/// assert_eq!(ByteOrder::from_little_endian(n), n.swap_bytes())
226-
/// }
227-
/// ```
228-
#[inline]
229-
fn from_little_endian(x: Self) -> Self {
230-
if cfg!(target_endian = "little") { x } else { x.swap_bytes() }
231-
}
232-
233-
/// Convert the value to big endian from the target's endianness.
234-
///
235-
/// On big endian this is a no-op. On little endian the bytes are swapped.
236-
///
237-
/// # Example
238-
///
239-
/// ```rust
240-
/// use std::mem::ByteOrder;
241-
///
242-
/// let n = 0x0123456789ABCDEFu64;
243-
///
244-
/// if cfg!(target_endian = "big") {
245-
/// assert_eq!(n.to_big_endian(), n)
246-
/// } else {
247-
/// assert_eq!(n.to_big_endian(), n.swap_bytes())
248-
/// }
249-
/// ```
250-
#[inline]
251-
fn to_big_endian(&self) -> Self {
252-
if cfg!(target_endian = "big") { self.clone() } else { self.swap_bytes() }
253-
}
254-
255-
/// Convert the value to little endian from the target's endianness.
256-
///
257-
/// On little endian this is a no-op. On big endian the bytes are swapped.
258-
///
259-
/// # Example
260-
///
261-
/// ```rust
262-
/// use std::mem::ByteOrder;
263-
///
264-
/// let n = 0x0123456789ABCDEFu64;
265-
///
266-
/// if cfg!(target_endian = "little") {
267-
/// assert_eq!(n.to_little_endian(), n)
268-
/// } else {
269-
/// assert_eq!(n.to_little_endian(), n.swap_bytes())
270-
/// }
271-
/// ```
272-
#[inline]
273-
fn to_little_endian(&self) -> Self {
274-
if cfg!(target_endian = "little") { self.clone() } else { self.swap_bytes() }
275-
}
276-
}
277-
278-
impl ByteOrder for u8 {
279-
#[inline]
280-
fn swap_bytes(&self) -> u8 {
281-
*self // swapping a single byte does nothing
282-
}
283-
}
284-
285-
impl ByteOrder for u16 {
286-
#[inline]
287-
fn swap_bytes(&self) -> u16 {
288-
unsafe { intrinsics::bswap16(*self) }
289-
}
290-
}
291-
292-
impl ByteOrder for u32 {
293-
#[inline]
294-
fn swap_bytes(&self) -> u32 {
295-
unsafe { intrinsics::bswap32(*self) }
296-
}
297-
}
298-
299-
impl ByteOrder for u64 {
300-
#[inline]
301-
fn swap_bytes(&self) -> u64 {
302-
unsafe { intrinsics::bswap64(*self) }
303-
}
304-
}
305-
306-
#[cfg(target_word_size = "32")]
307-
impl ByteOrder for uint {
308-
#[inline]
309-
fn swap_bytes(&self) -> uint {
310-
(*self as u32).swap_bytes() as uint
311-
}
312-
}
313-
314-
#[cfg(target_word_size = "64")]
315-
impl ByteOrder for uint {
316-
#[inline]
317-
fn swap_bytes(&self) -> uint {
318-
(*self as u64).swap_bytes() as uint
319-
}
320-
}
321-
322172
/// Convert an u16 to little endian from the target's endianness.
323173
///
324174
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
@@ -366,42 +216,42 @@ pub fn to_be64(x: u64) -> u64 { x.to_big_endian() }
366216
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
367217
#[inline]
368218
#[stable]
369-
pub fn from_le16(x: u16) -> u16 { ByteOrder::from_little_endian(x) }
219+
pub fn from_le16(x: u16) -> u16 { Int::from_little_endian(x) }
370220

371221
/// Convert an u32 from little endian to the target's endianness.
372222
///
373223
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
374224
#[inline]
375225
#[stable]
376-
pub fn from_le32(x: u32) -> u32 { ByteOrder::from_little_endian(x) }
226+
pub fn from_le32(x: u32) -> u32 { Int::from_little_endian(x) }
377227

378228
/// Convert an u64 from little endian to the target's endianness.
379229
///
380230
/// On little endian, this is a no-op. On big endian, the bytes are swapped.
381231
#[inline]
382232
#[stable]
383-
pub fn from_le64(x: u64) -> u64 { ByteOrder::from_little_endian(x) }
233+
pub fn from_le64(x: u64) -> u64 { Int::from_little_endian(x) }
384234

385235
/// Convert an u16 from big endian to the target's endianness.
386236
///
387237
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
388238
#[inline]
389239
#[stable]
390-
pub fn from_be16(x: u16) -> u16 { ByteOrder::from_big_endian(x) }
240+
pub fn from_be16(x: u16) -> u16 { Int::from_big_endian(x) }
391241

392242
/// Convert an u32 from big endian to the target's endianness.
393243
///
394244
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
395245
#[inline]
396246
#[stable]
397-
pub fn from_be32(x: u32) -> u32 { ByteOrder::from_big_endian(x) }
247+
pub fn from_be32(x: u32) -> u32 { Int::from_big_endian(x) }
398248

399249
/// Convert an u64 from big endian to the target's endianness.
400250
///
401251
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
402252
#[inline]
403253
#[stable]
404-
pub fn from_be64(x: u64) -> u64 { ByteOrder::from_big_endian(x) }
254+
pub fn from_be64(x: u64) -> u64 { Int::from_big_endian(x) }
405255

406256
/// Swap the values at two mutable locations of the same type, without
407257
/// deinitialising or copying either one.
@@ -642,60 +492,6 @@ mod tests {
642492
assert!(Vec::from_slice([76u8]) == transmute("L".to_string()));
643493
}
644494
}
645-
646-
macro_rules! test_byte_order {
647-
($T:ident) => {
648-
mod $T {
649-
use mem::ByteOrder;
650-
651-
static A: $T = 0b0101100;
652-
static B: $T = 0b0100001;
653-
static C: $T = 0b1111001;
654-
655-
static _0: $T = 0;
656-
static _1: $T = !0;
657-
658-
#[test]
659-
fn test_swap_bytes() {
660-
assert_eq!(A.swap_bytes().swap_bytes(), A);
661-
assert_eq!(B.swap_bytes().swap_bytes(), B);
662-
assert_eq!(C.swap_bytes().swap_bytes(), C);
663-
664-
// Swapping these should make no difference
665-
assert_eq!(_0.swap_bytes(), _0);
666-
assert_eq!(_1.swap_bytes(), _1);
667-
}
668-
669-
#[test]
670-
fn test_little_endian() {
671-
assert_eq!(ByteOrder::from_little_endian(A.to_little_endian()), A);
672-
assert_eq!(ByteOrder::from_little_endian(B.to_little_endian()), B);
673-
assert_eq!(ByteOrder::from_little_endian(C.to_little_endian()), C);
674-
assert_eq!(ByteOrder::from_little_endian(_0), _0);
675-
assert_eq!(ByteOrder::from_little_endian(_1), _1);
676-
assert_eq!(_0.to_little_endian(), _0);
677-
assert_eq!(_1.to_little_endian(), _1);
678-
}
679-
680-
#[test]
681-
fn test_big_endian() {
682-
assert_eq!(ByteOrder::from_big_endian(A.to_big_endian()), A);
683-
assert_eq!(ByteOrder::from_big_endian(B.to_big_endian()), B);
684-
assert_eq!(ByteOrder::from_big_endian(C.to_big_endian()), C);
685-
assert_eq!(ByteOrder::from_big_endian(_0), _0);
686-
assert_eq!(ByteOrder::from_big_endian(_1), _1);
687-
assert_eq!(_0.to_big_endian(), _0);
688-
assert_eq!(_1.to_big_endian(), _1);
689-
}
690-
}
691-
}
692-
}
693-
694-
test_byte_order!(u8)
695-
test_byte_order!(u16)
696-
test_byte_order!(u32)
697-
test_byte_order!(u64)
698-
test_byte_order!(uint)
699495
}
700496

701497
// FIXME #13642 (these benchmarks should be in another place)

0 commit comments

Comments
 (0)