Skip to content

Commit 8482d29

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

20 files changed

+52
-115
lines changed

doc/tutorial-tasks.md

+1-1
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

+2-7
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

+3-5
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

+2-3
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

+2-2
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

+1-1
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

+5-5
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

+1-1
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

+2-2
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

+1-1
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;

src/libstd/container.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use option::Option;
1616
/// knowledge known is the number of elements contained within.
1717
pub trait Container {
1818
/// Return the number of elements in the container
19-
fn len(&const self) -> uint;
19+
fn len(&self) -> uint;
2020

2121
/// Return true if the container contains no elements
22-
fn is_empty(&const self) -> bool;
22+
fn is_empty(&self) -> bool;
2323
}
2424

2525
/// A trait to represent mutable containers

src/libstd/io.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ impl Writer for BytesWriter {
16671667

16681668
fn seek(&self, offset: int, whence: SeekStyle) {
16691669
let pos = *self.pos;
1670-
let len = vec::uniq_len(&const *self.bytes);
1670+
let len = self.bytes.len();
16711671
*self.pos = seek_in_buf(offset, pos, len, whence);
16721672
}
16731673

src/libstd/old_iter.rs

-39
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ pub trait CopyableIter<A:Copy> {
5454
fn find(&self, p: &fn(&A) -> bool) -> Option<A>;
5555
}
5656

57-
pub trait CopyableOrderedIter<A:Copy + Ord> {
58-
fn min(&self) -> A;
59-
fn max(&self) -> A;
60-
}
61-
6257
// A trait for sequences that can be built by imperatively pushing elements
6358
// onto them.
6459
pub trait Buildable<A> {
@@ -192,40 +187,6 @@ pub fn position<A,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
192187
return None;
193188
}
194189

195-
// note: 'rposition' would only make sense to provide with a bidirectional
196-
// iter interface, such as would provide "reach" in addition to "each". As is,
197-
// it would have to be implemented with foldr, which is too inefficient.
198-
199-
#[inline(always)]
200-
pub fn min<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
201-
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {
202-
match a {
203-
&Some(ref a_) if *a_ < *b => {
204-
*(a)
205-
}
206-
_ => Some(*b)
207-
}
208-
} {
209-
Some(val) => val,
210-
None => fail!("min called on empty iterator")
211-
}
212-
}
213-
214-
#[inline(always)]
215-
pub fn max<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A {
216-
match do foldl::<A,Option<A>,IA>(this, None) |a, b| {
217-
match a {
218-
&Some(ref a_) if *a_ > *b => {
219-
*(a)
220-
}
221-
_ => Some(*b)
222-
}
223-
} {
224-
Some(val) => val,
225-
None => fail!("max called on empty iterator")
226-
}
227-
}
228-
229190
#[inline(always)]
230191
pub fn find<A:Copy,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool)
231192
-> Option<A> {

src/libstd/os.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1685,10 +1685,11 @@ mod tests {
16851685
assert!((ostream as uint != 0u));
16861686
let s = ~"hello";
16871687
let mut buf = s.as_bytes_with_null().to_owned();
1688+
let len = buf.len();
16881689
do vec::as_mut_buf(buf) |b, _len| {
1689-
assert!((libc::fwrite(b as *c_void, 1u as size_t,
1690-
(s.len() + 1u) as size_t, ostream)
1691-
== buf.len() as size_t))
1690+
assert_eq!(libc::fwrite(b as *c_void, 1u as size_t,
1691+
(s.len() + 1u) as size_t, ostream),
1692+
len as size_t)
16921693
}
16931694
assert_eq!(libc::fclose(ostream), (0u as c_int));
16941695
let in_mode = in.get_mode();

src/libstd/prelude.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ pub use char::Char;
4747
pub use container::{Container, Mutable, Map, Set};
4848
pub use hash::Hash;
4949
pub use old_iter::{BaseIter, ReverseIter, ExtendedIter, EqIter};
50-
pub use old_iter::{CopyableIter, CopyableOrderedIter};
50+
pub use old_iter::CopyableIter;
5151
pub use iter::{Times, FromIter};
52-
pub use iterator::{Iterator, IteratorUtil};
52+
pub use iterator::{Iterator, IteratorUtil, OrdIterator};
5353
pub use num::{Num, NumCast};
5454
pub use num::{Orderable, Signed, Unsigned, Round};
5555
pub use num::{Algebraic, Trigonometric, Exponential, Hyperbolic};

src/libstd/repr.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ More runtime type reflection
1818

1919
use cast::transmute;
2020
use char;
21+
use container::Container;
2122
use intrinsic;
2223
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
2324
use intrinsic::Opaque;
@@ -502,7 +503,7 @@ impl TyVisitor for ReprVisitor {
502503
_offset: uint,
503504
inner: *TyDesc)
504505
-> bool {
505-
match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] {
506+
match self.var_stk[self.var_stk.len() - 1] {
506507
Matched => {
507508
if i != 0 {
508509
self.writer.write_str(", ");
@@ -520,7 +521,7 @@ impl TyVisitor for ReprVisitor {
520521
_disr_val: int,
521522
n_fields: uint,
522523
_name: &str) -> bool {
523-
match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] {
524+
match self.var_stk[self.var_stk.len() - 1] {
524525
Matched => {
525526
if n_fields > 0 {
526527
self.writer.write_char(')');

src/libstd/rt/io/extensions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ impl<T: Reader> ReaderUtil for T {
297297

298298
do (|| {
299299
while total_read < len {
300-
let slice = vec::mut_slice(*buf, start_len + total_read, buf.len());
300+
let len = buf.len();
301+
let slice = vec::mut_slice(*buf, start_len + total_read, len);
301302
match self.read(slice) {
302303
Some(nread) => {
303304
total_read += nread;

src/libstd/vec.rs

+16-29
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ pub fn capacity<T>(v: &const ~[T]) -> uint {
118118
}
119119
}
120120

121-
// A botch to tide us over until core and std are fully demuted.
122-
#[allow(missing_doc)]
123-
pub fn uniq_len<T>(v: &const ~[T]) -> uint {
124-
unsafe {
125-
let v: &~[T] = transmute(v);
126-
as_const_buf(*v, |_p, len| len)
127-
}
128-
}
129-
130121
/**
131122
* Creates and initializes an owned vector.
132123
*
@@ -1767,19 +1758,32 @@ pub mod traits {
17671758
}
17681759
}
17691760

1770-
impl<'self,T> Container for &'self const [T] {
1761+
impl<'self, T> Container for &'self const [T] {
17711762
/// Returns true if a vector contains no elements
17721763
#[inline]
1773-
fn is_empty(&const self) -> bool {
1764+
fn is_empty(&self) -> bool {
17741765
as_const_buf(*self, |_p, len| len == 0u)
17751766
}
17761767

17771768
/// Returns the length of a vector
17781769
#[inline]
1779-
fn len(&const self) -> uint {
1770+
fn len(&self) -> uint {
17801771
as_const_buf(*self, |_p, len| len)
17811772
}
1773+
}
1774+
1775+
impl<T> Container for ~[T] {
1776+
/// Returns true if a vector contains no elements
1777+
#[inline]
1778+
fn is_empty(&self) -> bool {
1779+
as_const_buf(*self, |_p, len| len == 0u)
1780+
}
17821781

1782+
/// Returns the length of a vector
1783+
#[inline]
1784+
fn len(&self) -> uint {
1785+
as_const_buf(*self, |_p, len| len)
1786+
}
17831787
}
17841788

17851789
#[allow(missing_doc)]
@@ -2615,23 +2619,6 @@ impl<A:Copy> old_iter::CopyableIter<A> for @[A] {
26152619
}
26162620
}
26172621

2618-
impl<'self,A:Copy + Ord> old_iter::CopyableOrderedIter<A> for &'self [A] {
2619-
fn min(&self) -> A { old_iter::min(self) }
2620-
fn max(&self) -> A { old_iter::max(self) }
2621-
}
2622-
2623-
// FIXME(#4148): This should be redundant
2624-
impl<A:Copy + Ord> old_iter::CopyableOrderedIter<A> for ~[A] {
2625-
fn min(&self) -> A { old_iter::min(self) }
2626-
fn max(&self) -> A { old_iter::max(self) }
2627-
}
2628-
2629-
// FIXME(#4148): This should be redundant
2630-
impl<A:Copy + Ord> old_iter::CopyableOrderedIter<A> for @[A] {
2631-
fn min(&self) -> A { old_iter::min(self) }
2632-
fn max(&self) -> A { old_iter::max(self) }
2633-
}
2634-
26352622
impl<A:Clone> Clone for ~[A] {
26362623
#[inline]
26372624
fn clone(&self) -> ~[A] {

src/libsyntax/opt_vec.rs

-7
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,3 @@ impl<A: Copy> old_iter::CopyableIter<A> for OptVec<A> {
196196
old_iter::find(self, f)
197197
}
198198
}
199-
200-
impl<A: Copy+Ord> old_iter::CopyableOrderedIter<A> for OptVec<A> {
201-
#[inline(always)]
202-
fn min(&self) -> A { old_iter::min(self) }
203-
#[inline(always)]
204-
fn max(&self) -> A { old_iter::max(self) }
205-
}

0 commit comments

Comments
 (0)