Skip to content

Commit f56eb6c

Browse files
committed
---
yaml --- r: 68805 b: refs/heads/auto c: b5e9194 h: refs/heads/master i: 68803: d15ec34 v: v3
1 parent db4e712 commit f56eb6c

File tree

10 files changed

+70
-401
lines changed

10 files changed

+70
-401
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: db0a13b9865510ec07f7597e11009eabc2676afc
17+
refs/heads/auto: b5e9194836cab666163cf97cfbea6a323edad882
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/libextra/smallintmap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ impl<V> SmallIntMap<V> {
159159
/// Visit all key-value pairs in reverse order
160160
pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool {
161161
for uint::range_rev(self.v.len(), 0) |i| {
162-
match self.v[i] {
163-
Some(ref elt) => if !it(i, elt) { return false; },
162+
match self.v[i - 1] {
163+
Some(ref elt) => if !it(i - 1, elt) { return false; },
164164
None => ()
165165
}
166166
}

branches/auto/src/libstd/num/int_macros.rs

Lines changed: 19 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,28 @@ pub static bytes : uint = ($bits / 8);
2929
pub static min_value: $T = (-1 as $T) << (bits - 1);
3030
pub static max_value: $T = min_value - 1 as $T;
3131

32-
enum Range { Closed, HalfOpen }
33-
34-
#[inline]
3532
///
36-
/// Iterate through a range with a given step value.
33+
/// Iterate over the range [`lo`..`hi`)
3734
///
38-
/// Let `term` denote the closed interval `[stop-step,stop]` if `r` is Closed;
39-
/// otherwise `term` denotes the half-open interval `[stop-step,stop)`.
40-
/// Iterates through the range `[x_0, x_1, ..., x_n]` where
41-
/// `x_j == start + step*j`, and `x_n` lies in the interval `term`.
35+
/// # Arguments
4236
///
43-
/// If no such nonnegative integer `n` exists, then the iteration range
44-
/// is empty.
37+
/// * `lo` - lower bound, inclusive
38+
/// * `hi` - higher bound, exclusive
39+
///
40+
/// # Examples
41+
/// ~~~
42+
/// let mut sum = 0;
43+
/// for int::range(1, 5) |i| {
44+
/// sum += i;
45+
/// }
46+
/// assert!(sum == 10);
47+
/// ~~~
4548
///
46-
fn range_step_core(start: $T, stop: $T, step: $T, r: Range, it: &fn($T) -> bool) -> bool {
49+
#[inline]
50+
pub fn range_step(start: $T, stop: $T, step: $T, it: &fn($T) -> bool) -> bool {
4751
let mut i = start;
4852
if step == 0 {
4953
fail!(~"range_step called with step == 0");
50-
} else if step == (1 as $T) { // elide bounds check to tighten loop
51-
while i < stop {
52-
if !it(i) { return false; }
53-
// no need for overflow check;
54-
// cannot have i + 1 > max_value because i < stop <= max_value
55-
i += (1 as $T);
56-
}
57-
} else if step == (-1 as $T) { // elide bounds check to tighten loop
58-
while i > stop {
59-
if !it(i) { return false; }
60-
// no need for underflow check;
61-
// cannot have i - 1 < min_value because i > stop >= min_value
62-
i -= (1 as $T);
63-
}
6454
} else if step > 0 { // ascending
6555
while i < stop {
6656
if !it(i) { return false; }
@@ -76,66 +66,19 @@ fn range_step_core(start: $T, stop: $T, step: $T, r: Range, it: &fn($T) -> bool)
7666
i += step;
7767
}
7868
}
79-
match r {
80-
HalfOpen => return true,
81-
Closed => return (i != stop || it(i))
82-
}
83-
}
84-
85-
#[inline]
86-
///
87-
/// Iterate through the range [`start`..`stop`) with a given step value.
88-
///
89-
/// Iterates through the range `[x_0, x_1, ..., x_n]` where
90-
/// * `x_i == start + step*i`, and
91-
/// * `n` is the greatest nonnegative integer such that `x_n < stop`
92-
///
93-
/// (If no such `n` exists, then the iteration range is empty.)
94-
///
95-
/// # Arguments
96-
///
97-
/// * `start` - lower bound, inclusive
98-
/// * `stop` - higher bound, exclusive
99-
///
100-
/// # Examples
101-
/// ~~~
102-
/// let mut sum = 0;
103-
/// for int::range(1, 5) |i| {
104-
/// sum += i;
105-
/// }
106-
/// assert!(sum == 10);
107-
/// ~~~
108-
///
109-
pub fn range_step(start: $T, stop: $T, step: $T, it: &fn($T) -> bool) -> bool {
110-
range_step_core(start, stop, step, HalfOpen, it)
111-
}
112-
113-
#[inline]
114-
///
115-
/// Iterate through a range with a given step value.
116-
///
117-
/// Iterates through the range `[x_0, x_1, ..., x_n]` where
118-
/// `x_i == start + step*i` and `x_n <= last < step + x_n`.
119-
///
120-
/// (If no such nonnegative integer `n` exists, then the iteration
121-
/// range is empty.)
122-
///
123-
pub fn range_step_inclusive(start: $T, last: $T, step: $T, it: &fn($T) -> bool) -> bool {
124-
range_step_core(start, last, step, Closed, it)
69+
return true;
12570
}
12671
127-
12872
#[inline]
12973
/// Iterate over the range [`lo`..`hi`)
13074
pub fn range(lo: $T, hi: $T, it: &fn($T) -> bool) -> bool {
13175
range_step(lo, hi, 1 as $T, it)
13276
}
13377
13478
#[inline]
135-
/// Iterate over the range (`hi`..`lo`]
79+
/// Iterate over the range [`hi`..`lo`)
13680
pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool {
137-
if hi == min_value { return true; }
138-
range_step_inclusive(hi-1, lo, -1 as $T, it)
81+
range_step(hi, lo, -1 as $T, it)
13982
}
14083
14184
impl Num for $T {}
@@ -898,7 +841,7 @@ mod tests {
898841
for range(0,3) |i| {
899842
l.push(i);
900843
}
901-
for range_rev(14,11) |i| {
844+
for range_rev(13,10) |i| {
902845
l.push(i);
903846
}
904847
for range_step(20,26,2) |i| {

branches/auto/src/libstd/num/uint_macros.rs

Lines changed: 20 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -30,99 +30,40 @@ pub static bytes : uint = ($bits / 8);
3030
pub static min_value: $T = 0 as $T;
3131
pub static max_value: $T = 0 as $T - 1 as $T;
3232

33-
enum Range { Closed, HalfOpen }
34-
3533
#[inline]
36-
///
37-
/// Iterate through a range with a given step value.
38-
///
39-
/// Let `term` denote the closed interval `[stop-step,stop]` if `r` is Closed;
40-
/// otherwise `term` denotes the half-open interval `[stop-step,stop)`.
41-
/// Iterates through the range `[x_0, x_1, ..., x_n]` where
42-
/// `x_j == start + step*j`, and `x_n` lies in the interval `term`.
43-
///
44-
/// If no such nonnegative integer `n` exists, then the iteration range
45-
/// is empty.
46-
///
47-
fn range_step_core(start: $T, stop: $T, step: $T_SIGNED, r: Range, it: &fn($T) -> bool) -> bool {
34+
/**
35+
* Iterate through a range with a given step value.
36+
*
37+
* # Examples
38+
* ~~~ {.rust}
39+
* let nums = [1,2,3,4,5,6,7];
40+
*
41+
* for uint::range_step(0, nums.len() - 1, 2) |i| {
42+
* println(fmt!("%d & %d", nums[i], nums[i+1]));
43+
* }
44+
* ~~~
45+
*/
46+
pub fn range_step(start: $T, stop: $T, step: $T_SIGNED, it: &fn($T) -> bool) -> bool {
4847
let mut i = start;
4948
if step == 0 {
5049
fail!("range_step called with step == 0");
51-
} else if step == (1 as $T_SIGNED) { // elide bounds check to tighten loop
52-
while i < stop {
53-
if !it(i) { return false; }
54-
// no need for overflow check;
55-
// cannot have i + 1 > max_value because i < stop <= max_value
56-
i += (1 as $T);
57-
}
58-
} else if step == (-1 as $T_SIGNED) { // elide bounds check to tighten loop
59-
while i > stop {
60-
if !it(i) { return false; }
61-
// no need for underflow check;
62-
// cannot have i - 1 < min_value because i > stop >= min_value
63-
i -= (1 as $T);
64-
}
65-
} else if step > 0 { // ascending
50+
}
51+
if step >= 0 {
6652
while i < stop {
6753
if !it(i) { return false; }
6854
// avoiding overflow. break if i + step > max_value
6955
if i > max_value - (step as $T) { return true; }
7056
i += step as $T;
7157
}
72-
} else { // descending
58+
} else {
7359
while i > stop {
7460
if !it(i) { return false; }
7561
// avoiding underflow. break if i + step < min_value
7662
if i < min_value + ((-step) as $T) { return true; }
7763
i -= -step as $T;
7864
}
7965
}
80-
match r {
81-
HalfOpen => return true,
82-
Closed => return (i != stop || it(i))
83-
}
84-
}
85-
86-
#[inline]
87-
///
88-
/// Iterate through the range [`start`..`stop`) with a given step value.
89-
///
90-
/// Iterates through the range `[x_0, x_1, ..., x_n]` where
91-
/// - `x_i == start + step*i`, and
92-
/// - `n` is the greatest nonnegative integer such that `x_n < stop`
93-
///
94-
/// (If no such `n` exists, then the iteration range is empty.)
95-
///
96-
/// # Arguments
97-
///
98-
/// * `start` - lower bound, inclusive
99-
/// * `stop` - higher bound, exclusive
100-
///
101-
/// # Examples
102-
/// ~~~ {.rust}
103-
/// let nums = [1,2,3,4,5,6,7];
104-
///
105-
/// for uint::range_step(0, nums.len() - 1, 2) |i| {
106-
/// println(fmt!("%d & %d", nums[i], nums[i+1]));
107-
/// }
108-
/// ~~~
109-
///
110-
pub fn range_step(start: $T, stop: $T, step: $T_SIGNED, it: &fn($T) -> bool) -> bool {
111-
range_step_core(start, stop, step, HalfOpen, it)
112-
}
113-
114-
#[inline]
115-
///
116-
/// Iterate through a range with a given step value.
117-
///
118-
/// Iterates through the range `[x_0, x_1, ..., x_n]` where
119-
/// `x_i == start + step*i` and `x_n <= last < step + x_n`.
120-
///
121-
/// (If no such nonnegative integer `n` exists, then the iteration
122-
/// range is empty.)
123-
///
124-
pub fn range_step_inclusive(start: $T, last: $T, step: $T_SIGNED, it: &fn($T) -> bool) -> bool {
125-
range_step_core(start, last, step, Closed, it)
66+
return true;
12667
}
12768

12869
#[inline]
@@ -132,10 +73,9 @@ pub fn range(lo: $T, hi: $T, it: &fn($T) -> bool) -> bool {
13273
}
13374

13475
#[inline]
135-
/// Iterate over the range (`hi`..`lo`]
76+
/// Iterate over the range [`hi`..`lo`)
13677
pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool {
137-
if hi == min_value { return true; }
138-
range_step_inclusive(hi-1, lo, -1 as $T_SIGNED, it)
78+
range_step(hi, lo, -1 as $T_SIGNED, it)
13979
}
14080

14181
impl Num for $T {}
@@ -663,7 +603,7 @@ mod tests {
663603
for range(0,3) |i| {
664604
l.push(i);
665605
}
666-
for range_rev(14,11) |i| {
606+
for range_rev(13,10) |i| {
667607
l.push(i);
668608
}
669609
for range_step(20,26,2) |i| {

branches/auto/src/libstd/ptr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use cast;
1414
use option::{Option, Some, None};
1515
use sys;
1616
use unstable::intrinsics;
17+
use util::swap;
1718

1819
#[cfg(not(test))] use cmp::{Eq, Ord};
1920
use uint;
@@ -177,9 +178,9 @@ pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
177178
let t: *mut T = &mut tmp;
178179

179180
// Perform the swap
180-
copy_memory(t, x, 1);
181-
copy_memory(x, y, 1);
182-
copy_memory(y, t, 1);
181+
copy_nonoverlapping_memory(t, x, 1);
182+
copy_memory(x, y, 1); // `x` and `y` may overlap
183+
copy_nonoverlapping_memory(y, t, 1);
183184

184185
// y and t now point to the same thing, but we need to completely forget `tmp`
185186
// because it's no longer relevant.
@@ -192,7 +193,7 @@ pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
192193
*/
193194
#[inline]
194195
pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
195-
swap_ptr(dest, &mut src);
196+
swap(cast::transmute(dest), &mut src); // cannot overlap
196197
src
197198
}
198199

@@ -202,8 +203,7 @@ pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
202203
#[inline(always)]
203204
pub unsafe fn read_ptr<T>(src: *mut T) -> T {
204205
let mut tmp: T = intrinsics::uninit();
205-
let t: *mut T = &mut tmp;
206-
copy_memory(t, src, 1);
206+
copy_nonoverlapping_memory(&mut tmp, src, 1);
207207
tmp
208208
}
209209

branches/auto/src/libstd/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
669669
fail!("failure in dup3(err_fd, 2): %s", os::last_os_error());
670670
}
671671
// close all other fds
672-
for int::range_rev(getdtablesize() as int, 3) |fd| {
672+
for int::range_rev(getdtablesize() as int - 1, 2) |fd| {
673673
close(fd as c_int);
674674
}
675675

branches/auto/src/libstd/trie.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl<T> TrieNode<T> {
261261

262262
fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool {
263263
for uint::range_rev(self.children.len(), 0) |idx| {
264-
match self.children[idx] {
264+
match self.children[idx - 1] {
265265
Internal(ref x) => if !x.each_reverse(|i,t| f(i,t)) { return false },
266266
External(k, ref v) => if !f(&k, v) { return false },
267267
Nothing => ()

branches/auto/src/libstd/vec.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use option::{None, Option, Some};
2626
use ptr::to_unsafe_ptr;
2727
use ptr;
2828
use ptr::RawPtr;
29-
use rt::global_heap::realloc_raw;
29+
use rt::global_heap::{malloc_raw, realloc_raw};
3030
use sys;
3131
use sys::size_of;
3232
use uint;
@@ -95,12 +95,31 @@ pub fn to_owned<T:Copy>(t: &[T]) -> ~[T] {
9595
}
9696

9797
/// Creates a new vector with a capacity of `capacity`
98+
#[cfg(stage0)]
9899
pub fn with_capacity<T>(capacity: uint) -> ~[T] {
99100
let mut vec = ~[];
100101
vec.reserve(capacity);
101102
vec
102103
}
103104

105+
/// Creates a new vector with a capacity of `capacity`
106+
#[cfg(not(stage0))]
107+
pub fn with_capacity<T>(capacity: uint) -> ~[T] {
108+
unsafe {
109+
if contains_managed::<T>() {
110+
let mut vec = ~[];
111+
vec.reserve(capacity);
112+
vec
113+
} else {
114+
let alloc = capacity * sys::nonzero_size_of::<T>();
115+
let ptr = malloc_raw(alloc + size_of::<raw::VecRepr>()) as *mut raw::VecRepr;
116+
(*ptr).unboxed.alloc = alloc;
117+
(*ptr).unboxed.fill = 0;
118+
cast::transmute(ptr)
119+
}
120+
}
121+
}
122+
104123
/**
105124
* Builds a vector by calling a provided function with an argument
106125
* function that pushes an element to the back of a vector.

0 commit comments

Comments
 (0)