Skip to content

Commit 07feeb9

Browse files
committed
auto merge of #7487 : huonw/rust/vec-kill, r=cmr
Continuation of #7430. I haven't removed the `map` method, since the replacement `v.iter().transform(f).collect::<~[SomeType]>()` is a little ridiculous at the moment.
2 parents d5c5ce3 + c0a20d2 commit 07feeb9

Some content is hidden

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

68 files changed

+518
-899
lines changed

src/compiletest/runtest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
345345
fatal(~"process did not return an error status");
346346
}
347347

348-
let prefixes = vec::map(expected_errors, |ee| {
348+
let prefixes = expected_errors.iter().transform(|ee| {
349349
fmt!("%s:%u:", testfile.to_str(), ee.line)
350-
});
350+
}).collect::<~[~str]>();
351351

352352
// Scan and extract our error/warning messages,
353353
// which look like:

src/etc/unicode.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ def ch_prefix(ix):
122122

123123
def emit_bsearch_range_table(f):
124124
f.write("""
125-
pure fn bsearch_range_table(c: char, r: &[(char,char)]) -> bool {
126-
use cmp::{EQ, LT, GT};
127-
use vec::bsearch;
125+
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
126+
use cmp::{Equal, Less, Greater};
127+
use vec::ImmutableVector;
128128
use option::None;
129-
(do bsearch(r) |&(lo,hi)| {
130-
if lo <= c && c <= hi { EQ }
131-
else if hi < c { LT }
132-
else { GT }
129+
(do r.bsearch |&(lo,hi)| {
130+
if lo <= c && c <= hi { Equal }
131+
else if hi < c { Less }
132+
else { Greater }
133133
}) != None
134134
}\n\n
135135
""");
@@ -140,15 +140,15 @@ def emit_property_module(f, mod, tbl):
140140
keys.sort()
141141
emit_bsearch_range_table(f);
142142
for cat in keys:
143-
f.write(" const %s_table : &[(char,char)] = &[\n" % cat)
143+
f.write(" static %s_table : &'static [(char,char)] = &[\n" % cat)
144144
ix = 0
145145
for pair in tbl[cat]:
146146
f.write(ch_prefix(ix))
147147
f.write("(%s, %s)" % (escape_char(pair[0]), escape_char(pair[1])))
148148
ix += 1
149149
f.write("\n ];\n\n")
150150

151-
f.write(" pub pure fn %s(c: char) -> bool {\n" % cat)
151+
f.write(" pub fn %s(c: char) -> bool {\n" % cat)
152152
f.write(" bsearch_range_table(c, %s_table)\n" % cat)
153153
f.write(" }\n\n")
154154
f.write("}\n")
@@ -159,7 +159,7 @@ def emit_property_module_old(f, mod, tbl):
159159
keys = tbl.keys()
160160
keys.sort()
161161
for cat in keys:
162-
f.write(" pure fn %s(c: char) -> bool {\n" % cat)
162+
f.write(" fn %s(c: char) -> bool {\n" % cat)
163163
f.write(" ret alt c {\n")
164164
prefix = ' '
165165
for pair in tbl[cat]:
@@ -236,8 +236,22 @@ def emit_decomp_module(f, canon, compat):
236236

237237
(canon_decomp, compat_decomp, gencats) = load_unicode_data("UnicodeData.txt")
238238

239-
# Explain that the source code was generated by this script.
240-
rf.write('// The following code was generated by "src/etc/unicode.py"\n\n')
239+
# Preamble
240+
rf.write('''// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
241+
// file at the top-level directory of this distribution and at
242+
// http://rust-lang.org/COPYRIGHT.
243+
//
244+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
245+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
246+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
247+
// option. This file may not be copied, modified, or distributed
248+
// except according to those terms.
249+
250+
// The following code was generated by "src/etc/unicode.py"
251+
252+
#[allow(missing_doc)];
253+
254+
''')
241255

242256
emit_property_module(rf, "general_category", gencats)
243257

src/libextra/fileinput.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ total line count).
100100
use std::io::ReaderUtil;
101101
use std::io;
102102
use std::os;
103-
use std::vec;
104103

105104
/**
106105
A summary of the internal state of a `FileInput` object. `line_num`
@@ -353,13 +352,13 @@ a literal `-`.
353352
*/
354353
// XXX: stupid, unclear name
355354
pub fn pathify(vec: &[~str], stdin_hyphen : bool) -> ~[Option<Path>] {
356-
vec::map(vec, |&str : & ~str| {
357-
if stdin_hyphen && str == ~"-" {
355+
vec.iter().transform(|str| {
356+
if stdin_hyphen && "-" == *str {
358357
None
359358
} else {
360-
Some(Path(str))
359+
Some(Path(*str))
361360
}
362-
})
361+
}).collect()
363362
}
364363

365364
/**

src/libextra/getopts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ pub mod groups {
592592
*/
593593
pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str {
594594

595-
let desc_sep = ~"\n" + " ".repeat(24);
595+
let desc_sep = "\n" + " ".repeat(24);
596596

597-
let rows = vec::map(opts, |optref| {
597+
let mut rows = opts.iter().transform(|optref| {
598598
let OptGroup{short_name: short_name,
599599
long_name: long_name,
600600
hint: hint,
@@ -669,7 +669,7 @@ pub mod groups {
669669

670670
return str::to_owned(brief) +
671671
"\n\nOptions:\n" +
672-
rows.connect("\n") +
672+
rows.collect::<~[~str]>().connect("\n") +
673673
"\n\n";
674674
}
675675
} // end groups module

src/libextra/num/bigint.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ impl Mul<BigUint, BigUint> for BigUint {
283283
if n == 1 { return copy *a; }
284284

285285
let mut carry = 0;
286-
let prod = do vec::map(a.data) |ai| {
286+
let prod = do a.data.iter().transform |ai| {
287287
let (hi, lo) = BigDigit::from_uint(
288288
(*ai as uint) * (n as uint) + (carry as uint)
289289
);
290290
carry = hi;
291291
lo
292-
};
292+
}.collect::<~[BigDigit]>();
293293
if carry == 0 { return BigUint::new(prod) };
294294
return BigUint::new(prod + [carry]);
295295
}
@@ -618,13 +618,13 @@ impl BigUint {
618618
if n_bits == 0 || self.is_zero() { return copy *self; }
619619

620620
let mut carry = 0;
621-
let shifted = do vec::map(self.data) |elem| {
621+
let shifted = do self.data.iter().transform |elem| {
622622
let (hi, lo) = BigDigit::from_uint(
623623
(*elem as uint) << n_bits | (carry as uint)
624624
);
625625
carry = hi;
626626
lo
627-
};
627+
}.collect::<~[BigDigit]>();
628628
if carry == 0 { return BigUint::new(shifted); }
629629
return BigUint::new(shifted + [carry]);
630630
}
@@ -1172,7 +1172,7 @@ mod biguint_tests {
11721172
11731173
#[test]
11741174
fn test_cmp() {
1175-
let data = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ]
1175+
let data: ~[BigUint] = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ]
11761176
.map(|v| BigUint::from_slice(*v));
11771177
for data.iter().enumerate().advance |(i, ni)| {
11781178
for data.slice(i, data.len()).iter().enumerate().advance |(j0, nj)| {

src/libextra/par.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn map<A:Copy + Send,B:Copy + Send>(
9292
vec::concat(map_slices(xs, || {
9393
let f = fn_factory();
9494
let result: ~fn(uint, &[A]) -> ~[B] =
95-
|_, slice| vec::map(slice, |x| f(x));
95+
|_, slice| slice.iter().transform(|x| f(x)).collect();
9696
result
9797
}))
9898
}
@@ -104,9 +104,9 @@ pub fn mapi<A:Copy + Send,B:Copy + Send>(
104104
let slices = map_slices(xs, || {
105105
let f = fn_factory();
106106
let result: ~fn(uint, &[A]) -> ~[B] = |base, slice| {
107-
vec::mapi(slice, |i, x| {
107+
slice.iter().enumerate().transform(|(i, x)| {
108108
f(i + base, x)
109-
})
109+
}).collect()
110110
};
111111
result
112112
});

src/libextra/priority_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<T:Ord> PriorityQueue<T> {
107107
let mut end = q.len();
108108
while end > 1 {
109109
end -= 1;
110-
vec::swap(q.data, 0, end);
110+
q.data.swap(0, end);
111111
q.siftdown_range(0, end)
112112
}
113113
q.to_vec()

src/libextra/semver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ impl ToStr for Version {
7878
let s = if self.pre.is_empty() {
7979
s
8080
} else {
81-
s + "-" + self.pre.map(|i| i.to_str()).connect(".")
81+
fmt!("%s-%s", s, self.pre.map(|i| i.to_str()).connect("."))
8282
};
8383
if self.build.is_empty() {
8484
s
8585
} else {
86-
s + "+" + self.build.map(|i| i.to_str()).connect(".")
86+
fmt!("%s+%s", s, self.build.map(|i| i.to_str()).connect("."))
8787
}
8888
}
8989
}

src/libextra/smallintmap.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use std::cmp;
2020
use std::container::{Container, Mutable, Map, Set};
2121
use std::uint;
2222
use std::util::replace;
23-
use std::vec;
2423

2524
#[allow(missing_doc)]
2625
pub struct SmallIntMap<T> {
@@ -86,7 +85,7 @@ impl<V> Map<uint, V> for SmallIntMap<V> {
8685
let exists = self.contains_key(&key);
8786
let len = self.v.len();
8887
if len <= key {
89-
vec::grow_fn(&mut self.v, key - len + 1, |_| None);
88+
self.v.grow_fn(key - len + 1, |_| None);
9089
}
9190
self.v[key] = Some(value);
9291
!exists
@@ -383,8 +382,6 @@ mod test_set {
383382

384383
use super::SmallIntSet;
385384

386-
use std::vec;
387-
388385
#[test]
389386
fn test_disjoint() {
390387
let mut xs = SmallIntSet::new();
@@ -456,7 +453,7 @@ mod test_set {
456453
let mut i = 0;
457454
let expected = [3, 5, 11, 77];
458455
for a.intersection(&b) |x| {
459-
assert!(vec::contains(expected, x));
456+
assert!(expected.contains(x));
460457
i += 1
461458
}
462459
assert_eq!(i, expected.len());
@@ -479,7 +476,7 @@ mod test_set {
479476
let mut i = 0;
480477
let expected = [1, 5, 11];
481478
for a.difference(&b) |x| {
482-
assert!(vec::contains(expected, x));
479+
assert!(expected.contains(x));
483480
i += 1
484481
}
485482
assert_eq!(i, expected.len());
@@ -504,7 +501,7 @@ mod test_set {
504501
let mut i = 0;
505502
let expected = [1, 5, 11, 14, 22];
506503
for a.symmetric_difference(&b) |x| {
507-
assert!(vec::contains(expected, x));
504+
assert!(expected.contains(x));
508505
i += 1
509506
}
510507
assert_eq!(i, expected.len());
@@ -533,7 +530,7 @@ mod test_set {
533530
let mut i = 0;
534531
let expected = [1, 3, 5, 9, 11, 13, 16, 19, 24];
535532
for a.union(&b) |x| {
536-
assert!(vec::contains(expected, x));
533+
assert!(expected.contains(x));
537534
i += 1
538535
}
539536
assert_eq!(i, expected.len());

0 commit comments

Comments
 (0)