Skip to content

Commit d872969

Browse files
committed
---
yaml --- r: 130174 b: refs/heads/master c: d90921a h: refs/heads/master v: v3
1 parent ec4f8b0 commit d872969

File tree

32 files changed

+475
-711
lines changed

32 files changed

+475
-711
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 5924937a5a6d59baabb4f3d94b1cf5b2bf2136eb
2+
refs/heads/master: d90921a9d87b17df5eeab9e5f18581e8b04a1ba9
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 67b97ab6d2b7de9b69fd97dc171fcf8feec932ff
55
refs/heads/try: 28d5878c1f0465c11c8e7a3085008b0c592d48d0

trunk/src/libcollections/bitv.rs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ fn match_words <'a,'b>(a: &'a Bitv, b: &'b Bitv) -> (MatchWords<'a>, MatchWords<
9595
static TRUE: bool = true;
9696
static FALSE: bool = false;
9797

98+
#[deriving(Clone)]
99+
struct SmallBitv {
100+
/// only the lowest nbits of this value are used. the rest is undefined.
101+
bits: uint
102+
}
103+
104+
#[deriving(Clone)]
105+
struct BigBitv {
106+
storage: Vec<uint>
107+
}
108+
109+
#[deriving(Clone)]
110+
enum BitvVariant { Big(BigBitv), Small(SmallBitv) }
111+
98112
/// The bitvector type.
99113
///
100114
/// # Example
@@ -1639,7 +1653,6 @@ impl<'a> Iterator<uint> for TwoBitPositions<'a> {
16391653
#[cfg(test)]
16401654
mod tests {
16411655
use std::prelude::*;
1642-
use std::iter::range_step;
16431656
use std::uint;
16441657
use std::rand;
16451658
use std::rand::Rng;
@@ -2033,14 +2046,12 @@ mod tests {
20332046

20342047
#[test]
20352048
fn test_bitv_iterator() {
2036-
let bools = vec![true, false, true, true];
2049+
let bools = [true, false, true, true];
20372050
let bitv: Bitv = bools.iter().map(|n| *n).collect();
20382051

2039-
assert_eq!(bitv.iter().collect::<Vec<bool>>(), bools)
2040-
2041-
let long = Vec::from_fn(10000, |i| i % 2 == 0);
2042-
let bitv: Bitv = long.iter().map(|n| *n).collect();
2043-
assert_eq!(bitv.iter().collect::<Vec<bool>>(), long)
2052+
for (act, &ex) in bitv.iter().zip(bools.iter()) {
2053+
assert_eq!(ex, act);
2054+
}
20442055
}
20452056

20462057
#[test]
@@ -2050,12 +2061,6 @@ mod tests {
20502061

20512062
let idxs: Vec<uint> = bitv.iter().collect();
20522063
assert_eq!(idxs, vec!(0, 2, 3));
2053-
2054-
let long: BitvSet = range(0u, 10000).map(|n| n % 2 == 0).collect();
2055-
let real = range_step(0, 10000, 2).collect::<Vec<uint>>();
2056-
2057-
let idxs: Vec<uint> = long.iter().collect();
2058-
assert_eq!(idxs, real);
20592064
}
20602065

20612066
#[test]
@@ -2569,7 +2574,7 @@ mod tests {
25692574
}
25702575

25712576
#[bench]
2572-
fn bench_bitv_set_big_fixed(b: &mut Bencher) {
2577+
fn bench_bitv_big(b: &mut Bencher) {
25732578
let mut r = rng();
25742579
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
25752580
b.iter(|| {
@@ -2581,19 +2586,7 @@ mod tests {
25812586
}
25822587

25832588
#[bench]
2584-
fn bench_bitv_set_big_variable(b: &mut Bencher) {
2585-
let mut r = rng();
2586-
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
2587-
b.iter(|| {
2588-
for i in range(0u, 100) {
2589-
bitv.set((r.next_u32() as uint) % BENCH_BITS, r.gen());
2590-
}
2591-
&bitv
2592-
})
2593-
}
2594-
2595-
#[bench]
2596-
fn bench_bitv_set_small(b: &mut Bencher) {
2589+
fn bench_bitv_small(b: &mut Bencher) {
25972590
let mut r = rng();
25982591
let mut bitv = Bitv::with_capacity(uint::BITS, false);
25992592
b.iter(|| {
@@ -2605,7 +2598,7 @@ mod tests {
26052598
}
26062599

26072600
#[bench]
2608-
fn bench_bitvset_small(b: &mut Bencher) {
2601+
fn bench_bitv_set_small(b: &mut Bencher) {
26092602
let mut r = rng();
26102603
let mut bitv = BitvSet::new();
26112604
b.iter(|| {
@@ -2617,7 +2610,7 @@ mod tests {
26172610
}
26182611

26192612
#[bench]
2620-
fn bench_bitvset_big(b: &mut Bencher) {
2613+
fn bench_bitv_set_big(b: &mut Bencher) {
26212614
let mut r = rng();
26222615
let mut bitv = BitvSet::new();
26232616
b.iter(|| {

trunk/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<T> Rawlink<T> {
9090
/// Convert the `Rawlink` into an Option value
9191
fn resolve_immut<'a>(&self) -> Option<&'a T> {
9292
unsafe {
93-
self.p.as_ref()
93+
mem::transmute(self.p.to_option())
9494
}
9595
}
9696

trunk/src/libcore/ptr.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -256,46 +256,27 @@ pub unsafe fn position<T>(buf: *const T, f: |&T| -> bool) -> uint {
256256
pub trait RawPtr<T> {
257257
/// Returns the null pointer.
258258
fn null() -> Self;
259-
260259
/// Returns true if the pointer is equal to the null pointer.
261260
fn is_null(&self) -> bool;
262-
263261
/// Returns true if the pointer is not equal to the null pointer.
264262
fn is_not_null(&self) -> bool { !self.is_null() }
265-
266263
/// Returns the value of this pointer (ie, the address it points to)
267264
fn to_uint(&self) -> uint;
268-
269-
/// Returns `None` if the pointer is null, or else returns a reference to the
270-
/// value wrapped in `Some`.
265+
/// Returns `None` if the pointer is null, or else returns the value wrapped
266+
/// in `Some`.
271267
///
272268
/// # Safety Notes
273269
///
274-
/// While this method and its mutable counterpart are useful for null-safety,
275-
/// it is important to note that this is still an unsafe operation because
276-
/// the returned value could be pointing to invalid memory.
277-
unsafe fn as_ref<'a>(&self) -> Option<&'a T>;
278-
279-
/// A synonym for `as_ref`, except with incorrect lifetime semantics
280-
#[deprecated="Use `as_ref` instead"]
281-
unsafe fn to_option<'a>(&'a self) -> Option<&'a T> {
282-
mem::transmute(self.as_ref())
283-
}
284-
270+
/// While this method is useful for null-safety, it is important to note
271+
/// that this is still an unsafe operation because the returned value could
272+
/// be pointing to invalid memory.
273+
unsafe fn to_option(&self) -> Option<&T>;
285274
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
286275
/// the object, or one-byte-past-the-end. `count` is in units of T; e.g. a
287276
/// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
288277
unsafe fn offset(self, count: int) -> Self;
289278
}
290279

291-
/// Methods on mutable raw pointers
292-
pub trait RawMutPtr<T>{
293-
/// Returns `None` if the pointer is null, or else returns a mutable reference
294-
/// to the value wrapped in `Some`. As with `as_ref`, this is unsafe because
295-
/// it cannot verify the validity of the returned pointer.
296-
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T>;
297-
}
298-
299280
impl<T> RawPtr<T> for *const T {
300281
#[inline]
301282
fn null() -> *const T { null() }
@@ -312,7 +293,7 @@ impl<T> RawPtr<T> for *const T {
312293
}
313294

314295
#[inline]
315-
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
296+
unsafe fn to_option(&self) -> Option<&T> {
316297
if self.is_null() {
317298
None
318299
} else {
@@ -337,7 +318,7 @@ impl<T> RawPtr<T> for *mut T {
337318
}
338319

339320
#[inline]
340-
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
321+
unsafe fn to_option(&self) -> Option<&T> {
341322
if self.is_null() {
342323
None
343324
} else {
@@ -346,17 +327,6 @@ impl<T> RawPtr<T> for *mut T {
346327
}
347328
}
348329

349-
impl<T> RawMutPtr<T> for *mut T {
350-
#[inline]
351-
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
352-
if self.is_null() {
353-
None
354-
} else {
355-
Some(&mut **self)
356-
}
357-
}
358-
}
359-
360330
// Equality for pointers
361331
impl<T> PartialEq for *const T {
362332
#[inline]

trunk/src/libcoretest/ptr.rs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,44 +102,19 @@ fn test_is_null() {
102102
}
103103

104104
#[test]
105-
fn test_as_ref() {
105+
fn test_to_option() {
106106
unsafe {
107107
let p: *const int = null();
108-
assert_eq!(p.as_ref(), None);
108+
assert_eq!(p.to_option(), None);
109109

110110
let q: *const int = &2;
111-
assert_eq!(q.as_ref().unwrap(), &2);
111+
assert_eq!(q.to_option().unwrap(), &2);
112112

113113
let p: *mut int = mut_null();
114-
assert_eq!(p.as_ref(), None);
114+
assert_eq!(p.to_option(), None);
115115

116116
let q: *mut int = &mut 2;
117-
assert_eq!(q.as_ref().unwrap(), &2);
118-
119-
// Lifetime inference
120-
let u = 2i;
121-
{
122-
let p: *const int = &u as *const _;
123-
assert_eq!(p.as_ref().unwrap(), &2);
124-
}
125-
}
126-
}
127-
128-
#[test]
129-
fn test_as_mut() {
130-
unsafe {
131-
let p: *mut int = mut_null();
132-
assert!(p.as_mut() == None);
133-
134-
let q: *mut int = &mut 2;
135-
assert!(q.as_mut().unwrap() == &mut 2);
136-
137-
// Lifetime inference
138-
let mut u = 2i;
139-
{
140-
let p: *mut int = &mut u as *mut _;
141-
assert!(p.as_mut().unwrap() == &mut 2);
142-
}
117+
assert_eq!(q.to_option().unwrap(), &2);
143118
}
144119
}
145120

trunk/src/liblibc/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,14 +2965,12 @@ pub mod consts {
29652965
pub static AF_INET6: c_int = 10;
29662966
pub static SOCK_STREAM: c_int = 2;
29672967
pub static SOCK_DGRAM: c_int = 1;
2968-
pub static SOCK_RAW: c_int = 3;
29692968
pub static IPPROTO_TCP: c_int = 6;
29702969
pub static IPPROTO_IP: c_int = 0;
29712970
pub static IPPROTO_IPV6: c_int = 41;
29722971
pub static IP_MULTICAST_TTL: c_int = 33;
29732972
pub static IP_MULTICAST_LOOP: c_int = 34;
29742973
pub static IP_TTL: c_int = 2;
2975-
pub static IP_HDRINCL: c_int = 3;
29762974
pub static IP_ADD_MEMBERSHIP: c_int = 35;
29772975
pub static IP_DROP_MEMBERSHIP: c_int = 36;
29782976
pub static IPV6_ADD_MEMBERSHIP: c_int = 20;
@@ -3023,12 +3021,8 @@ pub mod consts {
30233021
pub mod extra {
30243022
use types::os::arch::c95::c_int;
30253023

3026-
pub static AF_PACKET : c_int = 17;
3027-
pub static IPPROTO_RAW : c_int = 255;
3028-
30293024
pub static O_RSYNC : c_int = 16400;
30303025
pub static O_DSYNC : c_int = 16;
3031-
pub static O_NONBLOCK : c_int = 128;
30323026
pub static O_SYNC : c_int = 16400;
30333027

30343028
pub static PROT_GROWSDOWN : c_int = 0x01000000;

trunk/src/liblog/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl Drop for DefaultLogger {
282282
pub fn log(level: u32, loc: &'static LogLocation, args: &fmt::Arguments) {
283283
// Test the literal string from args against the current filter, if there
284284
// is one.
285-
match unsafe { FILTER.as_ref() } {
285+
match unsafe { FILTER.to_option() } {
286286
Some(filter) if filter.is_match(args.to_string().as_slice()) => return,
287287
_ => {}
288288
}

0 commit comments

Comments
 (0)