提交 6c547e42 编写于 作者: D Daniel Micay

rm vec::uniq_len

上级 c989b791
...@@ -583,12 +583,12 @@ pub struct PipeByteChan { ...@@ -583,12 +583,12 @@ pub struct PipeByteChan {
impl BytePort for PipeBytePort { impl BytePort for PipeBytePort {
fn try_recv(&self, count: uint) -> Option<~[u8]> { 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, ~[]); let mut bytes = ::core::util::replace(&mut *self.buf, ~[]);
*self.buf = bytes.slice(count, bytes.len()).to_owned(); *self.buf = bytes.slice(count, bytes.len()).to_owned();
bytes.truncate(count); bytes.truncate(count);
return Some(bytes); 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, ~[]); let mut bytes = ::core::util::replace(&mut *self.buf, ~[]);
assert!(count > bytes.len()); assert!(count > bytes.len());
match self.try_recv(count - bytes.len()) { match self.try_recv(count - bytes.len()) {
...@@ -598,7 +598,7 @@ fn try_recv(&self, count: uint) -> Option<~[u8]> { ...@@ -598,7 +598,7 @@ fn try_recv(&self, count: uint) -> Option<~[u8]> {
} }
None => return None None => return None
} }
} else if vec::uniq_len(&const *self.buf) == 0 { } else /* empty */ {
match self.port.try_recv() { match self.port.try_recv() {
Some(buf) => { Some(buf) => {
assert!(!buf.is_empty()); assert!(!buf.is_empty());
...@@ -607,8 +607,6 @@ fn try_recv(&self, count: uint) -> Option<~[u8]> { ...@@ -607,8 +607,6 @@ fn try_recv(&self, count: uint) -> Option<~[u8]> {
} }
None => return None None => return None
} }
} else {
::core::util::unreachable()
} }
} }
} }
......
...@@ -879,8 +879,7 @@ fn read(&self, buf: &mut [u8], len: uint) -> uint { ...@@ -879,8 +879,7 @@ fn read(&self, buf: &mut [u8], len: uint) -> uint {
// If possible, copy up to `len` bytes from the internal // If possible, copy up to `len` bytes from the internal
// `data.buf` into `buf` // `data.buf` into `buf`
let nbuffered = vec::uniq_len(&const self.data.buf) - let nbuffered = self.data.buf.len() - self.data.buf_off;
self.data.buf_off;
let needed = len - count; let needed = len - count;
if nbuffered > 0 { if nbuffered > 0 {
unsafe { unsafe {
...@@ -934,7 +933,7 @@ fn read(&self, buf: &mut [u8], len: uint) -> uint { ...@@ -934,7 +933,7 @@ fn read(&self, buf: &mut [u8], len: uint) -> uint {
} }
fn read_byte(&self) -> int { fn read_byte(&self) -> int {
loop { 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]; let c = self.data.buf[self.data.buf_off];
self.data.buf_off += 1; self.data.buf_off += 1;
return c as int return c as int
......
...@@ -35,10 +35,10 @@ fn size_hint(&self) -> Option<uint> { self.data.size_hint() } ...@@ -35,10 +35,10 @@ fn size_hint(&self) -> Option<uint> { self.data.size_hint() }
impl<T:Ord> Container for PriorityQueue<T> { impl<T:Ord> Container for PriorityQueue<T> {
/// Returns the length of the queue /// 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 /// 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<T:Ord> Mutable for PriorityQueue<T> { impl<T:Ord> Mutable for PriorityQueue<T> {
......
...@@ -93,7 +93,7 @@ fn add_input(st: &mut Sha1State, msg: &const [u8]) { ...@@ -93,7 +93,7 @@ fn add_input(st: &mut Sha1State, msg: &const [u8]) {
} }
fn process_msg_block(st: &mut Sha1State) { fn process_msg_block(st: &mut Sha1State) {
assert_eq!(st.h.len(), digest_buf_len); 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 mut t: int; // Loop counter
let w = st.work_buf; let w = st.work_buf;
......
...@@ -32,9 +32,9 @@ pub struct SmallIntMap<T> { ...@@ -32,9 +32,9 @@ pub struct SmallIntMap<T> {
impl<V> Container for SmallIntMap<V> { impl<V> Container for SmallIntMap<V> {
/// Return the number of elements in the map /// Return the number of elements in the map
fn len(&const self) -> uint { fn len(&self) -> uint {
let mut sz = 0; 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] { match self.v[i] {
Some(_) => sz += 1, Some(_) => sz += 1,
None => {} None => {}
...@@ -44,7 +44,7 @@ fn len(&const self) -> uint { ...@@ -44,7 +44,7 @@ fn len(&const self) -> uint {
} }
/// Return true if the map contains no elements /// 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<V> Mutable for SmallIntMap<V> { impl<V> Mutable for SmallIntMap<V> {
...@@ -199,12 +199,12 @@ pub struct SmallIntSet { ...@@ -199,12 +199,12 @@ pub struct SmallIntSet {
impl Container for SmallIntSet { impl Container for SmallIntSet {
/// Return the number of elements in the map /// Return the number of elements in the map
fn len(&const self) -> uint { fn len(&self) -> uint {
self.map.len() self.map.len()
} }
/// Return true if the map contains no elements /// 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 { impl Mutable for SmallIntSet {
......
...@@ -365,7 +365,7 @@ fn write_pretty(out: @io::Writer, ...@@ -365,7 +365,7 @@ fn write_pretty(out: @io::Writer,
fn print_failures(st: &ConsoleTestState) { fn print_failures(st: &ConsoleTestState) {
st.out.write_line("\nfailures:"); st.out.write_line("\nfailures:");
let mut failures = ~[]; 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; let name = copy st.failures[i].name;
failures.push(name.to_str()); failures.push(name.to_str());
} }
......
...@@ -209,7 +209,7 @@ impl<T: Owned> Peekable<T> for PortSet<T> { ...@@ -209,7 +209,7 @@ impl<T: Owned> Peekable<T> for PortSet<T> {
fn peek(&self) -> bool { fn peek(&self) -> bool {
// It'd be nice to use self.port.each, but that version isn't // It'd be nice to use self.port.each, but that version isn't
// pure. // 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]; let port: &pipesy::Port<T> = &self.ports[i];
if port.peek() { if port.peek() {
return true; return true;
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
/// knowledge known is the number of elements contained within. /// knowledge known is the number of elements contained within.
pub trait Container { pub trait Container {
/// Return the number of elements in the 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 /// 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 /// A trait to represent mutable containers
......
...@@ -1667,7 +1667,7 @@ fn write(&self, v: &[u8]) { ...@@ -1667,7 +1667,7 @@ fn write(&self, v: &[u8]) {
fn seek(&self, offset: int, whence: SeekStyle) { fn seek(&self, offset: int, whence: SeekStyle) {
let pos = *self.pos; 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); *self.pos = seek_in_buf(offset, pos, len, whence);
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
use cast::transmute; use cast::transmute;
use char; use char;
use container::Container;
use intrinsic; use intrinsic;
use intrinsic::{TyDesc, TyVisitor, visit_tydesc}; use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
use intrinsic::Opaque; use intrinsic::Opaque;
...@@ -502,7 +503,7 @@ fn visit_enum_variant_field(&self, ...@@ -502,7 +503,7 @@ fn visit_enum_variant_field(&self,
_offset: uint, _offset: uint,
inner: *TyDesc) inner: *TyDesc)
-> bool { -> bool {
match self.var_stk[vec::uniq_len(&const *self.var_stk) - 1] { match self.var_stk[self.var_stk.len() - 1] {
Matched => { Matched => {
if i != 0 { if i != 0 {
self.writer.write_str(", "); self.writer.write_str(", ");
...@@ -520,7 +521,7 @@ fn visit_leave_enum_variant(&self, _variant: uint, ...@@ -520,7 +521,7 @@ fn visit_leave_enum_variant(&self, _variant: uint,
_disr_val: int, _disr_val: int,
n_fields: uint, n_fields: uint,
_name: &str) -> bool { _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 => { Matched => {
if n_fields > 0 { if n_fields > 0 {
self.writer.write_char(')'); self.writer.write_char(')');
......
...@@ -297,7 +297,8 @@ fn push_bytes(&mut self, buf: &mut ~[u8], len: uint) { ...@@ -297,7 +297,8 @@ fn push_bytes(&mut self, buf: &mut ~[u8], len: uint) {
do (|| { do (|| {
while total_read < len { 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) { match self.read(slice) {
Some(nread) => { Some(nread) => {
total_read += nread; total_read += nread;
......
...@@ -118,15 +118,6 @@ pub fn capacity<T>(v: &const ~[T]) -> uint { ...@@ -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. * Creates and initializes an owned vector.
* *
...@@ -1767,19 +1758,32 @@ fn add(&self, rhs: & &'self const [T]) -> ~[T] { ...@@ -1767,19 +1758,32 @@ fn add(&self, rhs: & &'self const [T]) -> ~[T] {
} }
} }
impl<'self,T> Container for &'self const [T] { impl<'self, T> Container for &'self const [T] {
/// Returns true if a vector contains no elements /// Returns true if a vector contains no elements
#[inline] #[inline]
fn is_empty(&const self) -> bool { fn is_empty(&self) -> bool {
as_const_buf(*self, |_p, len| len == 0u) as_const_buf(*self, |_p, len| len == 0u)
} }
/// Returns the length of a vector /// Returns the length of a vector
#[inline] #[inline]
fn len(&const self) -> uint { fn len(&self) -> uint {
as_const_buf(*self, |_p, len| len) 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)] #[allow(missing_doc)]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册