Skip to content

Commit 6c547e4

Browse files
committed
rm vec::uniq_len
1 parent c989b79 commit 6c547e4

File tree

12 files changed

+39
-36
lines changed

12 files changed

+39
-36
lines changed

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/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;

src/libstd/container.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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/repr.rs

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 16 additions & 12 deletions
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+
}
17821774

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+
}
1781+
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)]

0 commit comments

Comments
 (0)