Skip to content

Commit 7cfcb97

Browse files
committed
---
yaml --- r: 28668 b: refs/heads/try c: 3d59ac3 h: refs/heads/master v: v3
1 parent 9e4691e commit 7cfcb97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+409
-428
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
5-
refs/heads/try: f3c31a07d742478babfc7cda9d21ea6173ac2f6d
5+
refs/heads/try: 3d59ac3a1989c2d233b04cc8adc9b058690c2544
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df

branches/try/doc/tutorial.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ annotation:
426426
~~~~
427427
// The type of this vector will be inferred based on its use.
428428
let x = [];
429-
# vec::map(x, fn&(&&_y:int) -> int { _y });
429+
# vec::map(x, fn&(_y: &int) -> int { *_y });
430430
// Explicitly say this is a vector of zero integers.
431431
let y: [int * 0] = [];
432432
~~~~
@@ -1242,7 +1242,7 @@ for crayons.each |crayon| {
12421242
}
12431243
12441244
// Map vector elements
1245-
let crayon_names = crayons.map(|v| crayon_to_str(v));
1245+
let crayon_names = crayons.map(|v| crayon_to_str(*v));
12461246
let favorite_crayon_name = crayon_names[0];
12471247
12481248
// Remove whitespace from before and after the string
@@ -1298,7 +1298,7 @@ access local variables in the enclosing scope.
12981298

12991299
~~~~
13001300
let mut max = 0;
1301-
(~[1, 2, 3]).map(|x| if x > max { max = x });
1301+
(~[1, 2, 3]).map(|x| if *x > max { max = *x });
13021302
~~~~
13031303

13041304
Stack closures are very efficient because their environment is

branches/try/src/cargo/cargo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ fn is_uuid(id: ~str) -> bool {
195195
196196
match i {
197197
0u => {
198-
if str::len(part) == 8u {
198+
if part.len() == 8u {
199199
correct += 1u;
200200
}
201201
}
202202
1u | 2u | 3u => {
203-
if str::len(part) == 4u {
203+
if part.len() == 4u {
204204
correct += 1u;
205205
}
206206
}
207207
4u => {
208-
if str::len(part) == 12u {
208+
if part.len() == 12u {
209209
correct += 1u;
210210
}
211211
}

branches/try/src/libcore/dlist.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,12 @@ impl<T: Copy> DList<T> {
437437
/// Get data at the list's tail, failing if empty. O(1).
438438
pure fn tail() -> T { self.tail_n().data }
439439
/// Get the elements of the list as a vector. O(n).
440-
pure fn to_vec() -> ~[mut T] {
441-
let mut v = ~[mut];
440+
pure fn to_vec() -> ~[T] {
441+
let mut v = vec::with_capacity(self.size);
442442
unsafe {
443-
vec::reserve(v, self.size);
444443
// Take this out of the unchecked when iter's functions are pure
445444
for self.eachi |index,data| {
446-
v[index] = data;
445+
v[index] = *data;
447446
}
448447
}
449448
move v

branches/try/src/libcore/dvec.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ priv impl<A> DVec<A> {
117117
impl<A> DVec<A> {
118118
/// Reserves space for N elements
119119
fn reserve(count: uint) {
120-
vec::reserve(self.data, count)
120+
vec::reserve(&mut self.data, count)
121121
}
122122

123123
/**
@@ -243,7 +243,7 @@ impl<A: Copy> DVec<A> {
243243
do self.swap |v| {
244244
let mut v <- v;
245245
let new_len = vec::len(v) + to_idx - from_idx;
246-
vec::reserve(v, new_len);
246+
vec::reserve(&mut v, new_len);
247247
let mut i = from_idx;
248248
while i < to_idx {
249249
vec::push(v, ts[i]);
@@ -313,9 +313,9 @@ impl<A: Copy> DVec<A> {
313313
*/
314314
fn grow_set_elt(idx: uint, initval: A, val: A) {
315315
do self.swap |v| {
316-
let mut v = vec::to_mut(move v);
316+
let mut v = move v;
317317
vec::grow_set(v, idx, initval, val);
318-
move vec::from_mut(v)
318+
move v
319319
}
320320
}
321321
@@ -334,14 +334,28 @@ impl<A: Copy> DVec<A> {
334334

335335
/// Iterates over the elements in reverse order
336336
#[inline(always)]
337-
fn reach(f: fn(A) -> bool) {
338-
do self.swap |v| { vec::reach(v, f); move v }
337+
fn rev_each(f: fn(v: &A) -> bool) {
338+
do self.swap |v| {
339+
// FIXME(#2263)---we should be able to write
340+
// `vec::rev_each(v, f);` but we cannot write now
341+
for vec::rev_each(v) |e| {
342+
if !f(e) { break; }
343+
}
344+
move v
345+
}
339346
}
340347

341348
/// Iterates over the elements and indices in reverse order
342349
#[inline(always)]
343-
fn reachi(f: fn(uint, A) -> bool) {
344-
do self.swap |v| { vec::reachi(v, f); move v }
350+
fn rev_eachi(f: fn(uint, v: &A) -> bool) {
351+
do self.swap |v| {
352+
// FIXME(#2263)---we should be able to write
353+
// `vec::rev_eachi(v, f);` but we cannot write now
354+
for vec::rev_eachi(v) |i, e| {
355+
if !f(i, e) { break; }
356+
}
357+
move v
358+
}
345359
}
346360
}
347361

branches/try/src/libcore/io.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ trait ReaderUtil {
5252

5353
impl<T: Reader> T : ReaderUtil {
5454
fn read_bytes(len: uint) -> ~[u8] {
55-
let mut buf = ~[mut];
56-
vec::reserve(buf, len);
55+
let mut buf = vec::with_capacity(len);
5756
unsafe { vec::raw::set_len(buf, len); }
5857

5958
let count = self.read(buf, len);
6059

6160
unsafe { vec::raw::set_len(buf, count); }
62-
vec::from_mut(move buf)
61+
move buf
6362
}
6463
fn read_line() -> ~str {
6564
let mut buf = ~[];
@@ -696,7 +695,7 @@ impl BytesWriter: Writer {
696695
let buf_len = buf.len();
697696
698697
let count = uint::max(buf_len, self.pos + v_len);
699-
vec::reserve(buf, count);
698+
vec::reserve(&mut buf, count);
700699
unsafe { vec::raw::set_len(buf, count); }
701700
702701
let view = vec::mut_view(buf, self.pos, count);
@@ -910,7 +909,7 @@ mod tests {
910909
assert(vec::len(res) == len);
911910
}
912911
assert(vec::slice(ivals, 0u, vec::len(res)) ==
913-
vec::map(res, |x| x as int));
912+
vec::map(res, |x| *x as int));
914913
}
915914
}
916915
let mut i = 0u;

branches/try/src/libcore/iter-trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl<A> IMPL_T<A>: iter::BaseIter<A> {
1212
}
1313

1414
impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
15-
pure fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) }
15+
pure fn eachi(blk: fn(uint, v: &A) -> bool) { iter::eachi(self, blk) }
1616
pure fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
1717
pure fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
1818
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B {
@@ -32,7 +32,7 @@ impl<A: Copy> IMPL_T<A>: iter::CopyableIter<A> {
3232
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A] {
3333
iter::filter_to_vec(self, pred)
3434
}
35-
pure fn map_to_vec<B>(op: fn(A) -> B) -> ~[B] {
35+
pure fn map_to_vec<B>(op: fn(v: &A) -> B) -> ~[B] {
3636
iter::map_to_vec(self, op)
3737
}
3838
pure fn to_vec() -> ~[A] { iter::to_vec(self) }

branches/try/src/libcore/iter.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait BaseIter<A> {
1515
}
1616

1717
trait ExtendedIter<A> {
18-
pure fn eachi(blk: fn(uint, A) -> bool);
18+
pure fn eachi(blk: fn(uint, v: &A) -> bool);
1919
pure fn all(blk: fn(A) -> bool) -> bool;
2020
pure fn any(blk: fn(A) -> bool) -> bool;
2121
pure fn foldl<B>(+b0: B, blk: fn(B, A) -> B) -> B;
@@ -36,7 +36,7 @@ trait TimesIx{
3636

3737
trait CopyableIter<A:Copy> {
3838
pure fn filter_to_vec(pred: fn(A) -> bool) -> ~[A];
39-
pure fn map_to_vec<B>(op: fn(A) -> B) -> ~[B];
39+
pure fn map_to_vec<B>(op: fn(v: &A) -> B) -> ~[B];
4040
pure fn to_vec() -> ~[A];
4141
pure fn find(p: fn(A) -> bool) -> Option<A>;
4242
}
@@ -66,10 +66,10 @@ trait Buildable<A> {
6666
builder: fn(push: pure fn(+A))) -> self;
6767
}
6868

69-
pure fn eachi<A,IA:BaseIter<A>>(self: IA, blk: fn(uint, A) -> bool) {
69+
pure fn eachi<A,IA:BaseIter<A>>(self: IA, blk: fn(uint, v: &A) -> bool) {
7070
let mut i = 0u;
7171
for self.each |a| {
72-
if !blk(i, *a) { break; }
72+
if !blk(i, a) { break; }
7373
i += 1u;
7474
}
7575
}
@@ -97,11 +97,11 @@ pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: IA,
9797
}
9898
}
9999

100-
pure fn map_to_vec<A:Copy,B,IA:BaseIter<A>>(self: IA, op: fn(A) -> B)
100+
pure fn map_to_vec<A:Copy,B,IA:BaseIter<A>>(self: IA, op: fn(v: &A) -> B)
101101
-> ~[B] {
102102
do vec::build_sized_opt(self.size_hint()) |push| {
103103
for self.each |a| {
104-
push(op(*a));
104+
push(op(a));
105105
}
106106
}
107107
}

branches/try/src/libcore/os.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ fn list_dir(p: &Path) -> ~[~str] {
637637
* This version prepends each entry with the directory.
638638
*/
639639
fn list_dir_path(p: &Path) -> ~[~Path] {
640-
os::list_dir(p).map(|f| ~p.push(f))
640+
os::list_dir(p).map(|f| ~p.push(*f))
641641
}
642642
643643
/// Removes a directory at the specified path
@@ -721,9 +721,8 @@ fn copy_file(from: &Path, to: &Path) -> bool {
721721
fclose(istream);
722722
return false;
723723
}
724-
let mut buf : ~[mut u8] = ~[mut];
725724
let bufsize = 8192u;
726-
vec::reserve(buf, bufsize);
725+
let mut buf = vec::with_capacity::<u8>(bufsize);
727726
let mut done = false;
728727
let mut ok = true;
729728
while !done {

branches/try/src/libcore/result.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ impl<T: Copy, E: Copy> Result<T, E> {
269269
fn map_vec<T,U:Copy,V:Copy>(
270270
ts: &[T], op: fn((&T)) -> Result<V,U>) -> Result<~[V],U> {
271271

272-
let mut vs: ~[V] = ~[];
273-
vec::reserve(vs, vec::len(ts));
272+
let mut vs: ~[V] = vec::with_capacity(vec::len(ts));
274273
for vec::each(ts) |t| {
275274
match op(t) {
276275
Ok(v) => vec::push(vs, v),
@@ -306,8 +305,7 @@ fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
306305

307306
assert vec::same_length(ss, ts);
308307
let n = vec::len(ts);
309-
let mut vs = ~[];
310-
vec::reserve(vs, n);
308+
let mut vs = vec::with_capacity(n);
311309
let mut i = 0u;
312310
while i < n {
313311
match op(ss[i],ts[i]) {

branches/try/src/libcore/str.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,8 @@ pure fn lines(s: &str) -> ~[~str] { split_char(s, '\n') }
669669
*/
670670
pure fn lines_any(s: &str) -> ~[~str] {
671671
vec::map(lines(s), |s| {
672-
let l = len(s);
673-
let mut cp = copy s;
672+
let l = len(*s);
673+
let mut cp = copy *s;
674674
if l > 0u && s[l - 1u] == '\r' as u8 {
675675
unsafe { raw::set_len(&mut cp, l - 1u); }
676676
}
@@ -1984,7 +1984,7 @@ pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
19841984
fn reserve(s: &const ~str, n: uint) {
19851985
unsafe {
19861986
let v: *mut ~[u8] = cast::transmute(copy s);
1987-
vec::reserve(*v, n + 1);
1987+
vec::reserve(&mut *v, n + 1);
19881988
}
19891989
}
19901990

@@ -2077,10 +2077,8 @@ mod raw {
20772077

20782078
/// Create a Rust string from a *u8 buffer of the given length
20792079
unsafe fn from_buf_len(buf: *const u8, len: uint) -> ~str {
2080-
let mut v: ~[mut u8] = ~[mut];
2081-
vec::reserve(v, len + 1u);
2082-
vec::as_imm_buf(v, |vbuf, _len| {
2083-
let vbuf = ::cast::transmute_mut_unsafe(vbuf);
2080+
let mut v: ~[u8] = vec::with_capacity(len + 1);
2081+
vec::as_mut_buf(v, |vbuf, _len| {
20842082
ptr::memcpy(vbuf, buf as *u8, len)
20852083
});
20862084
vec::raw::set_len(v, len);
@@ -2132,8 +2130,7 @@ mod raw {
21322130
assert (begin <= end);
21332131
assert (end <= n);
21342132

2135-
let mut v = ~[];
2136-
vec::reserve(v, end - begin + 1u);
2133+
let mut v = vec::with_capacity(end - begin + 1u);
21372134
unsafe {
21382135
do vec::as_imm_buf(v) |vbuf, _vlen| {
21392136
let vbuf = ::cast::transmute_mut_unsafe(vbuf);

0 commit comments

Comments
 (0)