Skip to content

Commit 8482d29

Browse files
committed
auto merge of #7149 : thestinger/rust/vec, r=graydon
2 parents 5572023 + 7f00ab3 commit 8482d29

File tree

20 files changed

+52
-115
lines changed

20 files changed

+52
-115
lines changed

doc/tutorial-tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ fn pnorm(nums: &~[float], p: uint) -> float {
359359
360360
fn main() {
361361
let numbers = vec::from_fn(1000000, |_| rand::random::<float>());
362-
println(fmt!("Inf-norm = %?", numbers.max()));
362+
println(fmt!("Inf-norm = %?", *numbers.iter().max().unwrap()));
363363
364364
let numbers_arc = ARC(numbers);
365365

doc/tutorial.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,17 +2039,12 @@ themselves contain type parameters. A trait for generalized sequence
20392039
types might look like the following:
20402040

20412041
~~~~
2042-
# use std::vec;
20432042
trait Seq<T> {
2044-
fn len(&self) -> uint;
2045-
fn iter(&self, b: &fn(v: &T));
2043+
fn length(&self) -> uint;
20462044
}
20472045
20482046
impl<T> Seq<T> for ~[T] {
2049-
fn len(&self) -> uint { self.len() }
2050-
fn iter(&self, b: &fn(v: &T)) {
2051-
for vec::each(*self) |elt| { b(elt); }
2052-
}
2047+
fn length(&self) -> uint { self.len() }
20532048
}
20542049
~~~~
20552050

src/libextra/flatpipes.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,12 @@ pub mod bytepipes {
583583

584584
impl BytePort for PipeBytePort {
585585
fn try_recv(&self, count: uint) -> Option<~[u8]> {
586-
if vec::uniq_len(&const *self.buf) >= count {
586+
if self.buf.len() >= count {
587587
let mut bytes = ::core::util::replace(&mut *self.buf, ~[]);
588588
*self.buf = bytes.slice(count, bytes.len()).to_owned();
589589
bytes.truncate(count);
590590
return Some(bytes);
591-
} else if vec::uniq_len(&const *self.buf) > 0 {
591+
} else if !self.buf.is_empty() {
592592
let mut bytes = ::core::util::replace(&mut *self.buf, ~[]);
593593
assert!(count > bytes.len());
594594
match self.try_recv(count - bytes.len()) {
@@ -598,7 +598,7 @@ pub mod bytepipes {
598598
}
599599
None => return None
600600
}
601-
} else if vec::uniq_len(&const *self.buf) == 0 {
601+
} else /* empty */ {
602602
match self.port.try_recv() {
603603
Some(buf) => {
604604
assert!(!buf.is_empty());
@@ -607,8 +607,6 @@ pub mod bytepipes {
607607
}
608608
None => return None
609609
}
610-
} else {
611-
::core::util::unreachable()
612610
}
613611
}
614612
}

src/libextra/net_tcp.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,7 @@ impl io::Reader for TcpSocketBuf {
879879

880880
// If possible, copy up to `len` bytes from the internal
881881
// `data.buf` into `buf`
882-
let nbuffered = vec::uniq_len(&const self.data.buf) -
883-
self.data.buf_off;
882+
let nbuffered = self.data.buf.len() - self.data.buf_off;
884883
let needed = len - count;
885884
if nbuffered > 0 {
886885
unsafe {
@@ -934,7 +933,7 @@ impl io::Reader for TcpSocketBuf {
934933
}
935934
fn read_byte(&self) -> int {
936935
loop {
937-
if vec::uniq_len(&const self.data.buf) > self.data.buf_off {
936+
if self.data.buf.len() > self.data.buf_off {
938937
let c = self.data.buf[self.data.buf_off];
939938
self.data.buf_off += 1;
940939
return c as int

src/libextra/priority_queue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ impl<T:Ord> BaseIter<T> for PriorityQueue<T> {
3535

3636
impl<T:Ord> Container for PriorityQueue<T> {
3737
/// Returns the length of the queue
38-
fn len(&const self) -> uint { vec::uniq_len(&const self.data) }
38+
fn len(&self) -> uint { self.data.len() }
3939

4040
/// Returns true if a queue contains no elements
41-
fn is_empty(&const self) -> bool { self.len() == 0 }
41+
fn is_empty(&self) -> bool { self.len() == 0 }
4242
}
4343

4444
impl<T:Ord> Mutable for PriorityQueue<T> {

src/libextra/sha1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn sha1() -> @Sha1 {
9393
}
9494
fn process_msg_block(st: &mut Sha1State) {
9595
assert_eq!(st.h.len(), digest_buf_len);
96-
assert_eq!(vec::uniq_len(st.work_buf), work_buf_len);
96+
assert_eq!(st.work_buf.len(), work_buf_len);
9797
let mut t: int; // Loop counter
9898
let w = st.work_buf;
9999

src/libextra/smallintmap.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ pub struct SmallIntMap<T> {
3232

3333
impl<V> Container for SmallIntMap<V> {
3434
/// Return the number of elements in the map
35-
fn len(&const self) -> uint {
35+
fn len(&self) -> uint {
3636
let mut sz = 0;
37-
for uint::range(0, vec::uniq_len(&const self.v)) |i| {
37+
for uint::range(0, self.v.len()) |i| {
3838
match self.v[i] {
3939
Some(_) => sz += 1,
4040
None => {}
@@ -44,7 +44,7 @@ impl<V> Container for SmallIntMap<V> {
4444
}
4545

4646
/// Return true if the map contains no elements
47-
fn is_empty(&const self) -> bool { self.len() == 0 }
47+
fn is_empty(&self) -> bool { self.len() == 0 }
4848
}
4949

5050
impl<V> Mutable for SmallIntMap<V> {
@@ -199,12 +199,12 @@ pub struct SmallIntSet {
199199

200200
impl Container for SmallIntSet {
201201
/// Return the number of elements in the map
202-
fn len(&const self) -> uint {
202+
fn len(&self) -> uint {
203203
self.map.len()
204204
}
205205

206206
/// Return true if the map contains no elements
207-
fn is_empty(&const self) -> bool { self.len() == 0 }
207+
fn is_empty(&self) -> bool { self.len() == 0 }
208208
}
209209

210210
impl Mutable for SmallIntSet {

src/libextra/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ pub fn run_tests_console(opts: &TestOpts,
365365
fn print_failures(st: &ConsoleTestState) {
366366
st.out.write_line("\nfailures:");
367367
let mut failures = ~[];
368-
for uint::range(0, vec::uniq_len(&const st.failures)) |i| {
368+
for uint::range(0, st.failures.len()) |i| {
369369
let name = copy st.failures[i].name;
370370
failures.push(name.to_str());
371371
}

src/librustc/middle/trans/adt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
165165
if cases.all(|c| c.tys.len() == 0) {
166166
// All bodies empty -> intlike
167167
let discrs = cases.map(|c| c.discr);
168-
return CEnum(discrs.min(), discrs.max());
168+
return CEnum(*discrs.iter().min().unwrap(), *discrs.iter().max().unwrap());
169169
}
170170

171171
if cases.len() == 1 {
@@ -509,7 +509,7 @@ pub fn trans_const(ccx: &mut CrateContext, r: &Repr, discr: int,
509509
}
510510
General(ref cases) => {
511511
let case = &cases[discr as uint];
512-
let max_sz = cases.map(|s| s.size).max();
512+
let max_sz = cases.iter().transform(|x| x.size).max().unwrap();
513513
let discr_ty = C_int(ccx, discr);
514514
let contents = build_const_struct(ccx, case,
515515
~[discr_ty] + vals);

src/libstd/comm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
209209
fn peek(&self) -> bool {
210210
// It'd be nice to use self.port.each, but that version isn't
211211
// pure.
212-
for uint::range(0, vec::uniq_len(&const self.ports)) |i| {
212+
for uint::range(0, self.ports.len()) |i| {
213213
let port: &pipesy::Port<T> = &self.ports[i];
214214
if port.peek() {
215215
return true;

0 commit comments

Comments
 (0)