From 6c547e42c859b1b0051293c48c691d8388bad332 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 15 Jun 2013 02:20:06 -0400 Subject: [PATCH] rm vec::uniq_len --- src/libextra/flatpipes.rs | 8 +++----- src/libextra/net_tcp.rs | 5 ++--- src/libextra/priority_queue.rs | 4 ++-- src/libextra/sha1.rs | 2 +- src/libextra/smallintmap.rs | 10 +++++----- src/libextra/test.rs | 2 +- src/libstd/comm.rs | 2 +- src/libstd/container.rs | 4 ++-- src/libstd/io.rs | 2 +- src/libstd/repr.rs | 5 +++-- src/libstd/rt/io/extensions.rs | 3 ++- src/libstd/vec.rs | 28 ++++++++++++++++------------ 12 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/libextra/flatpipes.rs b/src/libextra/flatpipes.rs index c0f619c1b85..4ff67fc3f42 100644 --- a/src/libextra/flatpipes.rs +++ b/src/libextra/flatpipes.rs @@ -583,12 +583,12 @@ pub mod bytepipes { impl BytePort for PipeBytePort { fn try_recv(&self, count: uint) -> Option<~[u8]> { - if vec::uniq_len(&const *self.buf) >= count { + if self.buf.len() >= count { let mut bytes = ::core::util::replace(&mut *self.buf, ~[]); *self.buf = bytes.slice(count, bytes.len()).to_owned(); bytes.truncate(count); return Some(bytes); - } else if vec::uniq_len(&const *self.buf) > 0 { + } else if !self.buf.is_empty() { let mut bytes = ::core::util::replace(&mut *self.buf, ~[]); assert!(count > bytes.len()); match self.try_recv(count - bytes.len()) { @@ -598,7 +598,7 @@ pub mod bytepipes { } None => return None } - } else if vec::uniq_len(&const *self.buf) == 0 { + } else /* empty */ { match self.port.try_recv() { Some(buf) => { assert!(!buf.is_empty()); @@ -607,8 +607,6 @@ pub mod bytepipes { } None => return None } - } else { - ::core::util::unreachable() } } } diff --git a/src/libextra/net_tcp.rs b/src/libextra/net_tcp.rs index d95807f2b91..28b3700399a 100644 --- a/src/libextra/net_tcp.rs +++ b/src/libextra/net_tcp.rs @@ -879,8 +879,7 @@ impl io::Reader for TcpSocketBuf { // If possible, copy up to `len` bytes from the internal // `data.buf` into `buf` - let nbuffered = vec::uniq_len(&const self.data.buf) - - self.data.buf_off; + let nbuffered = self.data.buf.len() - self.data.buf_off; let needed = len - count; if nbuffered > 0 { unsafe { @@ -934,7 +933,7 @@ impl io::Reader for TcpSocketBuf { } fn read_byte(&self) -> int { loop { - if vec::uniq_len(&const self.data.buf) > self.data.buf_off { + if self.data.buf.len() > self.data.buf_off { let c = self.data.buf[self.data.buf_off]; self.data.buf_off += 1; return c as int diff --git a/src/libextra/priority_queue.rs b/src/libextra/priority_queue.rs index 601b7685f3c..efbf23f11b1 100644 --- a/src/libextra/priority_queue.rs +++ b/src/libextra/priority_queue.rs @@ -35,10 +35,10 @@ impl BaseIter for PriorityQueue { impl Container for PriorityQueue { /// Returns the length of the queue - fn len(&const self) -> uint { vec::uniq_len(&const self.data) } + fn len(&self) -> uint { self.data.len() } /// Returns true if a queue contains no elements - fn is_empty(&const self) -> bool { self.len() == 0 } + fn is_empty(&self) -> bool { self.len() == 0 } } impl Mutable for PriorityQueue { diff --git a/src/libextra/sha1.rs b/src/libextra/sha1.rs index 908e497b959..0c35630345b 100644 --- a/src/libextra/sha1.rs +++ b/src/libextra/sha1.rs @@ -93,7 +93,7 @@ pub fn sha1() -> @Sha1 { } fn process_msg_block(st: &mut Sha1State) { assert_eq!(st.h.len(), digest_buf_len); - assert_eq!(vec::uniq_len(st.work_buf), work_buf_len); + assert_eq!(st.work_buf.len(), work_buf_len); let mut t: int; // Loop counter let w = st.work_buf; diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index 7f566bc16e7..dae9113b3a9 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -32,9 +32,9 @@ pub struct SmallIntMap { impl Container for SmallIntMap { /// Return the number of elements in the map - fn len(&const self) -> uint { + fn len(&self) -> uint { let mut sz = 0; - for uint::range(0, vec::uniq_len(&const self.v)) |i| { + for uint::range(0, self.v.len()) |i| { match self.v[i] { Some(_) => sz += 1, None => {} @@ -44,7 +44,7 @@ impl Container for SmallIntMap { } /// Return true if the map contains no elements - fn is_empty(&const self) -> bool { self.len() == 0 } + fn is_empty(&self) -> bool { self.len() == 0 } } impl Mutable for SmallIntMap { @@ -199,12 +199,12 @@ pub struct SmallIntSet { impl Container for SmallIntSet { /// Return the number of elements in the map - fn len(&const self) -> uint { + fn len(&self) -> uint { self.map.len() } /// Return true if the map contains no elements - fn is_empty(&const self) -> bool { self.len() == 0 } + fn is_empty(&self) -> bool { self.len() == 0 } } impl Mutable for SmallIntSet { diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 406dfb086ea..a465cef09e6 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -365,7 +365,7 @@ pub fn run_tests_console(opts: &TestOpts, fn print_failures(st: &ConsoleTestState) { st.out.write_line("\nfailures:"); let mut failures = ~[]; - for uint::range(0, vec::uniq_len(&const st.failures)) |i| { + for uint::range(0, st.failures.len()) |i| { let name = copy st.failures[i].name; failures.push(name.to_str()); } 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 Peekable for PortSet { 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 = &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/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 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..44f3fc4c321 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -118,15 +118,6 @@ pub fn capacity(v: &const ~[T]) -> uint { } } -// A botch to tide us over until core and std are fully demuted. -#[allow(missing_doc)] -pub fn uniq_len(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 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)]