diff options
| author | bors <bors@rust-lang.org> | 2013-06-15 23:10:12 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-06-15 23:10:12 -0700 |
| commit | 8482d29d9b27a00e2d84bbf3bc0a3d14c61e34ba (patch) | |
| tree | 2f9642874bcf470b735cb179be96ecbd77db56e3 /src/libstd | |
| parent | 5572023cd868c5b6045bc91355cd21465c59ff6d (diff) | |
| parent | 7f00ab3df10b8b648872edf25fb1700168b306de (diff) | |
| download | rust-8482d29d9b27a00e2d84bbf3bc0a3d14c61e34ba.tar.gz rust-8482d29d9b27a00e2d84bbf3bc0a3d14c61e34ba.zip | |
auto merge of #7149 : thestinger/rust/vec, r=graydon
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/comm.rs | 2 | ||||
| -rw-r--r-- | src/libstd/container.rs | 4 | ||||
| -rw-r--r-- | src/libstd/io.rs | 2 | ||||
| -rw-r--r-- | src/libstd/old_iter.rs | 39 | ||||
| -rw-r--r-- | src/libstd/os.rs | 7 | ||||
| -rw-r--r-- | src/libstd/prelude.rs | 4 | ||||
| -rw-r--r-- | src/libstd/repr.rs | 5 | ||||
| -rw-r--r-- | src/libstd/rt/io/extensions.rs | 3 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 45 |
9 files changed, 31 insertions, 80 deletions
diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index f0c353c8d62..bcdd6cd0bfa 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -209,7 +209,7 @@ impl<T: Owned> Peekable<T> for PortSet<T> { fn peek(&self) -> bool { // It'd be nice to use self.port.each, but that version isn't // pure. - for uint::range(0, vec::uniq_len(&const self.ports)) |i| { + for uint::range(0, self.ports.len()) |i| { let port: &pipesy::Port<T> = &self.ports[i]; if port.peek() { return true; diff --git a/src/libstd/container.rs b/src/libstd/container.rs index 065582e2e0d..c1b656f1cd9 100644 --- a/src/libstd/container.rs +++ b/src/libstd/container.rs @@ -16,10 +16,10 @@ use option::Option; /// knowledge known is the number of elements contained within. pub trait Container { /// Return the number of elements in the container - fn len(&const self) -> uint; + fn len(&self) -> uint; /// Return true if the container contains no elements - fn is_empty(&const self) -> bool; + fn is_empty(&self) -> bool; } /// A trait to represent mutable containers diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 6f065d74fa2..d3faa75e3b0 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -1667,7 +1667,7 @@ impl Writer for BytesWriter { fn seek(&self, offset: int, whence: SeekStyle) { let pos = *self.pos; - let len = vec::uniq_len(&const *self.bytes); + let len = self.bytes.len(); *self.pos = seek_in_buf(offset, pos, len, whence); } diff --git a/src/libstd/old_iter.rs b/src/libstd/old_iter.rs index 9fea4376816..347b4774422 100644 --- a/src/libstd/old_iter.rs +++ b/src/libstd/old_iter.rs @@ -54,11 +54,6 @@ pub trait CopyableIter<A:Copy> { fn find(&self, p: &fn(&A) -> bool) -> Option<A>; } -pub trait CopyableOrderedIter<A:Copy + Ord> { - fn min(&self) -> A; - fn max(&self) -> A; -} - // A trait for sequences that can be built by imperatively pushing elements // onto them. pub trait Buildable<A> { @@ -192,40 +187,6 @@ pub fn position<A,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool) return None; } -// note: 'rposition' would only make sense to provide with a bidirectional -// iter interface, such as would provide "reach" in addition to "each". As is, -// it would have to be implemented with foldr, which is too inefficient. - -#[inline(always)] -pub fn min<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A { - match do foldl::<A,Option<A>,IA>(this, None) |a, b| { - match a { - &Some(ref a_) if *a_ < *b => { - *(a) - } - _ => Some(*b) - } - } { - Some(val) => val, - None => fail!("min called on empty iterator") - } -} - -#[inline(always)] -pub fn max<A:Copy + Ord,IA:BaseIter<A>>(this: &IA) -> A { - match do foldl::<A,Option<A>,IA>(this, None) |a, b| { - match a { - &Some(ref a_) if *a_ > *b => { - *(a) - } - _ => Some(*b) - } - } { - Some(val) => val, - None => fail!("max called on empty iterator") - } -} - #[inline(always)] pub fn find<A:Copy,IA:BaseIter<A>>(this: &IA, f: &fn(&A) -> bool) -> Option<A> { diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 044b305a0dd..fffcb34dc09 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1685,10 +1685,11 @@ mod tests { assert!((ostream as uint != 0u)); let s = ~"hello"; let mut buf = s.as_bytes_with_null().to_owned(); + let len = buf.len(); do vec::as_mut_buf(buf) |b, _len| { - assert!((libc::fwrite(b as *c_void, 1u as size_t, - (s.len() + 1u) as size_t, ostream) - == buf.len() as size_t)) + assert_eq!(libc::fwrite(b as *c_void, 1u as size_t, + (s.len() + 1u) as size_t, ostream), + len as size_t) } assert_eq!(libc::fclose(ostream), (0u as c_int)); let in_mode = in.get_mode(); diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 61b8d36266e..60165ed5dae 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -47,9 +47,9 @@ pub use char::Char; pub use container::{Container, Mutable, Map, Set}; pub use hash::Hash; pub use old_iter::{BaseIter, ReverseIter, ExtendedIter, EqIter}; -pub use old_iter::{CopyableIter, CopyableOrderedIter}; +pub use old_iter::CopyableIter; pub use iter::{Times, FromIter}; -pub use iterator::{Iterator, IteratorUtil}; +pub use iterator::{Iterator, IteratorUtil, OrdIterator}; pub use num::{Num, NumCast}; pub use num::{Orderable, Signed, Unsigned, Round}; pub use num::{Algebraic, Trigonometric, Exponential, Hyperbolic}; diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index 46f69d020d1..b7ff1acea13 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -18,6 +18,7 @@ More runtime type reflection use cast::transmute; use char; +use container::Container; use intrinsic; use intrinsic::{TyDesc, TyVisitor, visit_tydesc}; use intrinsic::Opaque; @@ -502,7 +503,7 @@ impl TyVisitor for ReprVisitor { _offset: uint, inner: *TyDesc) -> bool { - match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { + match self.var_stk[self.var_stk.len() - 1] { Matched => { if i != 0 { self.writer.write_str(", "); @@ -520,7 +521,7 @@ impl TyVisitor for ReprVisitor { _disr_val: int, n_fields: uint, _name: &str) -> bool { - match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { + match self.var_stk[self.var_stk.len() - 1] { Matched => { if n_fields > 0 { self.writer.write_char(')'); diff --git a/src/libstd/rt/io/extensions.rs b/src/libstd/rt/io/extensions.rs index 727ab13a4f6..a5e68bcdac4 100644 --- a/src/libstd/rt/io/extensions.rs +++ b/src/libstd/rt/io/extensions.rs @@ -297,7 +297,8 @@ impl<T: Reader> ReaderUtil for T { do (|| { while total_read < len { - let slice = vec::mut_slice(*buf, start_len + total_read, buf.len()); + let len = buf.len(); + let slice = vec::mut_slice(*buf, start_len + total_read, len); match self.read(slice) { Some(nread) => { total_read += nread; diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 211ee12c291..7b4764164b5 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -118,15 +118,6 @@ pub fn capacity<T>(v: &const ~[T]) -> uint { } } -// A botch to tide us over until core and std are fully demuted. -#[allow(missing_doc)] -pub fn uniq_len<T>(v: &const ~[T]) -> uint { - unsafe { - let v: &~[T] = transmute(v); - as_const_buf(*v, |_p, len| len) - } -} - /** * Creates and initializes an owned vector. * @@ -1767,19 +1758,32 @@ pub mod traits { } } -impl<'self,T> Container for &'self const [T] { +impl<'self, T> Container for &'self const [T] { /// Returns true if a vector contains no elements #[inline] - fn is_empty(&const self) -> bool { + fn is_empty(&self) -> bool { as_const_buf(*self, |_p, len| len == 0u) } /// Returns the length of a vector #[inline] - fn len(&const self) -> uint { + fn len(&self) -> uint { as_const_buf(*self, |_p, len| len) } +} + +impl<T> Container for ~[T] { + /// Returns true if a vector contains no elements + #[inline] + fn is_empty(&self) -> bool { + as_const_buf(*self, |_p, len| len == 0u) + } + /// Returns the length of a vector + #[inline] + fn len(&self) -> uint { + as_const_buf(*self, |_p, len| len) + } } #[allow(missing_doc)] @@ -2615,23 +2619,6 @@ impl<A:Copy> old_iter::CopyableIter<A> for @[A] { } } -impl<'self,A:Copy + Ord> old_iter::CopyableOrderedIter<A> for &'self [A] { - fn min(&self) -> A { old_iter::min(self) } - fn max(&self) -> A { old_iter::max(self) } -} - -// FIXME(#4148): This should be redundant -impl<A:Copy + Ord> old_iter::CopyableOrderedIter<A> for ~[A] { - fn min(&self) -> A { old_iter::min(self) } - fn max(&self) -> A { old_iter::max(self) } -} - -// FIXME(#4148): This should be redundant -impl<A:Copy + Ord> old_iter::CopyableOrderedIter<A> for @[A] { - fn min(&self) -> A { old_iter::min(self) } - fn max(&self) -> A { old_iter::max(self) } -} - impl<A:Clone> Clone for ~[A] { #[inline] fn clone(&self) -> ~[A] { |
